上传文件不保存在数据库中

编程入门 行业动态 更新时间:2024-10-27 10:22:54
本文介绍了上传文件不保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尝试上传文件并保存在目录和数据库中,当我上传文件时,它保存在目录中但不在数据库中这里是上传文件代码

try to upload document and save in directory and in database also when i upload document it saves in directory but not in database here is upload document code

if (FileUploadControl.PostedFile != null && FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.PostedFile.FileName); string folder = Server.MapPath("~/Docfiles/"); Directory.CreateDirectory(folder); FileUploadControl.PostedFile.SaveAs(Path.Combine(folder, filename)); try { up.fileupladdd(Txt_docde.Value, txt_dname.Value, FileUploadControl.FileName, Convert.ToInt32(DropDownList1.SelectedValue), Convert.ToInt32(DropDownList2.SelectedValue), Convert.ToInt32(Session["UserID"]),Convert.ToString(Session["UserID"])); StatusLabel.Text = "Success"; } catch { StatusLabel.Text = "Failed"; } } Txt_docde.Value = ""; txt_dname.Value = "";

和sp上传文件是

and sp of upload file is

ALTER procedure [dbo].[fileuplaod] @DocDesciption nvarchar(50), @DocName nvarchar(50), @Uploadfile nvarchar(50), @DocTypeID int, @DepID int, @UserID int as insert into DocumentInfo(DocDesciption ,DocName,Uploadfile,DocTypeID,DepID ,UserID) values(@DocDesciption,@DocName,@Uploadfile,@DocTypeID,@DepID ,@UserID)

where出现问题?

where is the problem occur?

推荐答案

我认为您的存储过程调用可能有问题。尝试这样的事情 I think your stored procedure call may be problematic. try something like this SqlConnection PubsConn = new SqlConnection ("your connection string here"); SqlCommand testCMD = new SqlCommand ("fileuplaod", PubsConn); testCMD.CommandType = CommandType.StoredProcedure; SqlParameter DocDesc = testCMD.Parameters.Add ("@DocDesciption", SqlDbType.NVarChar, 50); DocDesc.Direction = ParameterDirection.Input; SqlParameter DocName= testCMD.Parameters.Add ("@DocName ", SqlDbType.NVarChar, 50); DocName.Direction = ParameterDirection.Input; // Add other parameters as well DocDesc.Value = "set document description here"; DocName.Value = "set document name here"; //set other parameter values here PubsConn.Open(); testCMD.ExecuteNonQuery ().ToString() ;

Convert.ToInt32(Session["UserID"]),Convert.ToString(Session["UserID"]));

这里存在错误,因为你发送了两次相同的参数而你的方法只有6个参数

the error exist here because you send the same argument twice and your method has 6 paramater only

public void fileupladdd(string DocDesc, string Docname, string file, int doctypeid, int depid, int UserID, string UploadedBy) { //db.ExecuteNonQuery("fileuplaod", new object[] { DocDesc, Docname, file, doctypeid, depid, UserID, UploadedBy }); Hashtable hash = new Hashtable(); hash.Add("@DocDesc", DocDesc); hash.Add("@Docname", Docname); hash.Add("@file", file); hash.Add("@doctypeid", doctypeid); hash.Add("@depid", depid); hash.Add("@UserID", UserID); hash.Add("@UploadedBy", UploadedBy); ExecuteStoreProcedure("youspname here", hash); } public int ExecuteStoreProcedure(string spName, Hashtable param) { try { using (_DbConn = new SqlConnection(_sConString)) { _DbConn.Open(); SqlCommand _DbCommand = new SqlCommand(); _DbCommand.CommandText = spName; _DbCommand.CommandType = CommandType.StoredProcedure; _DbCommand.Connection = _DbConn; foreach (string para in param.Keys) { _DbCommand.Parameters.AddWithValue(para, param[para]); } return _DbCommand.ExecuteNonQuery(); } } catch (Exception) { throw; } }

更多推荐

上传文件不保存在数据库中

本文发布于:2023-11-07 01:17:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   不保存   上传文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!