且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-15 12:34:27

我认为您的存储过程调用可能有问题。尝试这样的事情



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;
           }
       }