Click here to Skip to main content
16,013,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one table called documentrequest and this is the data on it,
TrID int Unchecked
RequestBy varchar(20) Checked
DocumentCode varchar(20) Checked
RequestDate datetime Checked
RequiredDate datetime Checked
ReturnDate datetime Checked
Remark varchar(500) Checked
Status int Checked.

Now I want to add files for each TrID. for that I create the new table called DocumentRequestForm
DocReqID int Unchecked
TrID int Checked
FileName varchar(150) Checked
StoredName varchar(150) Checked
DisplayName varchar(500) Checked
FileType varchar(100) Checked
FileSize int Checked.

how I can update each TrID.

this is my save code for document request

C#
protected void btnSave_Click(object sender, EventArgs e)
        {
            var str = ValidateSubmit();
            if (str == "")
            {
                DateTime dt1 = new DateTime();
                dt1 = new DateTime(Convert.ToInt32(txtRequiredOn.Text.Split('/')[2].ToString()), Convert.ToInt32(txtRequiredOn.Text.Split('/')[1].ToString()), Convert.ToInt32(txtRequiredOn.Text.Split('/')[0].ToString()));

                DateTime dt2 = new DateTime();
                dt2 = new DateTime(Convert.ToInt32(txtReturnOn.Text.Split('/')[2].ToString()), Convert.ToInt32(txtReturnOn.Text.Split('/')[1].ToString()), Convert.ToInt32(txtReturnOn.Text.Split('/')[0].ToString()));
                
                Hashtable objHt = new Hashtable();
                objHt.Add("@TrMode", "IE");
                objHt.Add("@RequestBy", Session["empid"].ToString());
                objHt.Add("@DocumentCode", drpDocumentType.SelectedValue);
                objHt.Add("@RequiredDate", dt1);
                objHt.Add("@ReturnDate", dt2);
                objHt.Add("@Remark", txtReason.Text);
                objHt.Add("@Status", 1);

                DB.ExecuteSPorSQLNonQuery("InUpTrDocumentRequest", ref objHt, 1);

                dvSuccess.Visible = true;
                dvSuccess.InnerHtml = "Your request has been submitted successfully.";
                btnSave.Visible = false;
               

            }
            else
            {
                dvError.Visible = true;
                dvError.InnerHtml = str;
            }

        }

InUpTrDocumentRequest is storedprocedure...

please give me idea. I am new to file upload.
Posted
Updated 27-Oct-14 6:46am
v2
Comments
Richard Deeming 27-Oct-14 16:24pm    
Your code for converting a string to a date isn't very robust. Try using the DateTime.TryParseExact method[^] instead.

DateTime dt1;
if (!DateTime.TryParseExact(txtRequiredOn.Text, "dd/MM/yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out dt1))
{
// The string is not a valid date.
// Display an error message and exit.
}
tastini 28-Oct-14 7:13am    
I have no issues with date function there...

1 solution

If you want to store file into database, then you should have one column with binary DataType. Then you should store the byte data of the file in that column.

There are many examples available in internet. Below is one of them.
hSave Files to SQL Server Database using FileUpload Control[^]
 
Share this answer
 
Comments
tastini 27-Oct-14 13:32pm    
I got it , but I am asking how I can upload under that column"TrID" you saw my second table? simply adding the one file to database there is 100 example I guess I can follow them but am getting trouble in this issue. please recheck.
TrID is one int field. You can't store a file in int field. You have to add one new column as binary DataType and store the byte data in that. Got me?
tastini 27-Oct-14 13:47pm    
no I am not saying I want to store in TrID , may b you misunderstand me, this is the table of requesting some documents, I want to add signed request form with it. TrID is the key for both table. bcoz I have data already in first table, the second table is new. I can edit the second table. but how to achieve it? how I can add the request forms for all my old data. its like update the data with files.
How will you take files from users? Or you have all files in a folder?
tastini 28-Oct-14 7:13am    
users will update when they request the document

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



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