Click here to Skip to main content
15,882,464 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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

C#
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 = "";

and sp of upload file is

C#
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 is the problem occur?
Posted
Comments
Richard C Bishop 30-Sep-13 17:28pm    
You are not calling your stored procedure anywhere in the code you provided.
Diya Ayesa 30-Sep-13 17:35pm    
and then this function i call in code
Diya Ayesa 30-Sep-13 17:35pm    
i call my sp in function this is
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 });


}
MuhammadUSman1 30-Sep-13 23:46pm    
You should execute Store Procedure using code to save values in Data Base.
MuhammadUSman1 1-Oct-13 0:00am    
I add solution please check if any issue let me know.

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() ;
 
Share this answer
 
C#
Convert.ToInt32(Session["UserID"]),Convert.ToString(Session["UserID"]));


the error exist here because you send the same argument twice and your method has 6 paramater only
 
Share this answer
 
v2
Comments
Diya Ayesa 1-Oct-13 9:42am    
i remove last one but it still nt upload documents
C#
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;
           }
       }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900