Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have this code

C#
con.ConnectionString = "Data Source=aaaa;Initial Catalog=aaa;User ID=aaa;Password=aaa";
                con.Open();
                SqlCommand cmd = new SqlCommand("exec doc_record @PO_NUMBER, @Path,@Time_Saved, @Scanned_BY", con);
                // cmd.Parameters.AddWithValue("@PO_NUMBER", Label4.Text);
                cmd.Parameters.Add("@PO_NUMBER", SqlDbType.VarChar, 250).Value = Label4.Text;
                cmd.Parameters.Add("@Path", SqlDbType.NVarChar).Value = NewFileName;
                cmd.Parameters.Add("@Time_Saved", SqlDbType.NVarChar).Value = "";
                cmd.Parameters.Add("@Scanned_BY", SqlDbType.NVarChar).Value = Environment.UserName;
                cmd.ExecuteNonQuery();
                con.Close();
                confirm();


What I have tried:

There is a textbox to save the PO Number. So when i enter this PO number in the text box "645-5263038-O9-SMIPLX" and press save. The letter 'X' gets trimmed everytime and it is saved as "645-5263038-O9-SMIPL" but if i enter it manually in the database then there is now problem. Before the length of the field was set to Varchar(20) but now i have exceeded it to Varchar(100) but there still is a problem.
Posted
Updated 20-Oct-16 5:06am
Comments
[no name] 20-Oct-16 10:35am    
Look at doc_record and see what it's doing.
Saaharjit Singh 20-Oct-16 11:01am    
Thanks! :)
jgakenhe 20-Oct-16 10:52am    
Yes, the parameter size in your stored procedure @PO_NUMBER is probably the wrong size. If the column was not big enough, then you'd get an exception like: "String or binary data would be truncated. The statement has been terminated."
Saaharjit Singh 20-Oct-16 11:01am    
Thanks:)
ZurdoDev 20-Oct-16 11:03am    
Go ahead and post that as solution.

1 solution

Yes, the parameter size in your stored procedure @PO_NUMBER is probably the wrong size; it will need to be increased to at least the size of the textbox or the maximum size of the data which you are passing in. If the column was not big enough, then you'd get an exception like: "String or binary data would be truncated. The statement has been terminated."
 
Share this answer
 
Comments
Karthik_Mahalingam 20-Oct-16 12:15pm    
5
jgakenhe 20-Oct-16 12:20pm    
Thanks! The sad thing is I'm on holiday, but I am starting to transition back into work mode; so I thought I'd mess around CP a bit tonight.
Karthik_Mahalingam 20-Oct-16 12:21pm    
:)

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