error String or binary data would be truncated.
-
hi i m using asp.net c# n i m trying to save data in to data base it give error at time of save code is cmd.CommandText = "select invoice_no from invoice where invoice_no=(select Max(invoice_no) from invoice)"; adp.Fill(ds, "dm"); foreach (DataRow dm in ds.Tables["dm"].Rows) { Label2.Text = dm["invoice_no"].ToString(); } Label2.Text = Convert.ToString( Convert.ToInt32(Label2.Text) + 1); // add in the table material incoming cmd.CommandText = "Select * from invoice"; adp.Fill(ds, "re"); dr = ds.Tables["re"].NewRow(); cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); dr = ds.Tables["re"].NewRow(); dr["invoice_no"] = Convert.ToString(l); //dr["enterby"] = Label64.Text; //ddlinby.SelectedIndex.ToString(); dr["po_no"] = TextBox2.Text; dr["dc_no"] = TextBox3.Text; dr["comp_name"] = TextBox4.Text; dr["comp_add"] = TextBox5.Text; dr["tin_no"] = TextBox42.Text; dr["total_vat"] = TextBox34.Text; dr["prod1"] = TextBox35.Text; dr["prod2"] = TextBox36.Text; dr["prod3"] = TextBox37.Text; dr["prod4"] = TextBox38.Text; dr["prod5"] = TextBox39.Text; dr["prod6"] = TextBox40.Text; dr["prod1_q"] = TextBox12.Text; dr["prod2_q"] = TextBox13.Text; dr["prod3_q"] = TextBox14.Text; dr["prod4_q"] = TextBox15.Text; dr["prod5_q"] = TextBox16.Text; dr["prod6_q"] = TextBox17.Text; dr["prod1_p"] = TextBox18.Text; dr["prod2_p"] = TextBox19.Text; dr["prod3_p"] = TextBox20.Text; dr["prod4_p"] = TextBox21.Text; dr["prod5_p"] = TextBox22.Text; dr["prod6_p"] = TextBox23.Text; dr["vat"] = TextBox31.Text; dr["total"] = TextBox30.Text; dr["price"] = TextBox33.Text; ds.Tables["re"].Rows.Add(dr); cmd.CommandText = "Select * from invoice"; cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); and error is String or binary data would be truncated.The statement has been terminated. at this line adp.Update(ds.Tables["re"]); pls help me
-
hi i m using asp.net c# n i m trying to save data in to data base it give error at time of save code is cmd.CommandText = "select invoice_no from invoice where invoice_no=(select Max(invoice_no) from invoice)"; adp.Fill(ds, "dm"); foreach (DataRow dm in ds.Tables["dm"].Rows) { Label2.Text = dm["invoice_no"].ToString(); } Label2.Text = Convert.ToString( Convert.ToInt32(Label2.Text) + 1); // add in the table material incoming cmd.CommandText = "Select * from invoice"; adp.Fill(ds, "re"); dr = ds.Tables["re"].NewRow(); cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); dr = ds.Tables["re"].NewRow(); dr["invoice_no"] = Convert.ToString(l); //dr["enterby"] = Label64.Text; //ddlinby.SelectedIndex.ToString(); dr["po_no"] = TextBox2.Text; dr["dc_no"] = TextBox3.Text; dr["comp_name"] = TextBox4.Text; dr["comp_add"] = TextBox5.Text; dr["tin_no"] = TextBox42.Text; dr["total_vat"] = TextBox34.Text; dr["prod1"] = TextBox35.Text; dr["prod2"] = TextBox36.Text; dr["prod3"] = TextBox37.Text; dr["prod4"] = TextBox38.Text; dr["prod5"] = TextBox39.Text; dr["prod6"] = TextBox40.Text; dr["prod1_q"] = TextBox12.Text; dr["prod2_q"] = TextBox13.Text; dr["prod3_q"] = TextBox14.Text; dr["prod4_q"] = TextBox15.Text; dr["prod5_q"] = TextBox16.Text; dr["prod6_q"] = TextBox17.Text; dr["prod1_p"] = TextBox18.Text; dr["prod2_p"] = TextBox19.Text; dr["prod3_p"] = TextBox20.Text; dr["prod4_p"] = TextBox21.Text; dr["prod5_p"] = TextBox22.Text; dr["prod6_p"] = TextBox23.Text; dr["vat"] = TextBox31.Text; dr["total"] = TextBox30.Text; dr["price"] = TextBox33.Text; ds.Tables["re"].Rows.Add(dr); cmd.CommandText = "Select * from invoice"; cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); and error is String or binary data would be truncated.The statement has been terminated. at this line adp.Update(ds.Tables["re"]); pls help me
Hi, You are trying to save a value whose size is exceeded the maximum limit set for the column in which it is going to be saved. Check all values which you are setting in the datarow. Some value may be crossing their expected size. Regards Saanj
Either you love IT or leave IT...
-
hi i m using asp.net c# n i m trying to save data in to data base it give error at time of save code is cmd.CommandText = "select invoice_no from invoice where invoice_no=(select Max(invoice_no) from invoice)"; adp.Fill(ds, "dm"); foreach (DataRow dm in ds.Tables["dm"].Rows) { Label2.Text = dm["invoice_no"].ToString(); } Label2.Text = Convert.ToString( Convert.ToInt32(Label2.Text) + 1); // add in the table material incoming cmd.CommandText = "Select * from invoice"; adp.Fill(ds, "re"); dr = ds.Tables["re"].NewRow(); cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); dr = ds.Tables["re"].NewRow(); dr["invoice_no"] = Convert.ToString(l); //dr["enterby"] = Label64.Text; //ddlinby.SelectedIndex.ToString(); dr["po_no"] = TextBox2.Text; dr["dc_no"] = TextBox3.Text; dr["comp_name"] = TextBox4.Text; dr["comp_add"] = TextBox5.Text; dr["tin_no"] = TextBox42.Text; dr["total_vat"] = TextBox34.Text; dr["prod1"] = TextBox35.Text; dr["prod2"] = TextBox36.Text; dr["prod3"] = TextBox37.Text; dr["prod4"] = TextBox38.Text; dr["prod5"] = TextBox39.Text; dr["prod6"] = TextBox40.Text; dr["prod1_q"] = TextBox12.Text; dr["prod2_q"] = TextBox13.Text; dr["prod3_q"] = TextBox14.Text; dr["prod4_q"] = TextBox15.Text; dr["prod5_q"] = TextBox16.Text; dr["prod6_q"] = TextBox17.Text; dr["prod1_p"] = TextBox18.Text; dr["prod2_p"] = TextBox19.Text; dr["prod3_p"] = TextBox20.Text; dr["prod4_p"] = TextBox21.Text; dr["prod5_p"] = TextBox22.Text; dr["prod6_p"] = TextBox23.Text; dr["vat"] = TextBox31.Text; dr["total"] = TextBox30.Text; dr["price"] = TextBox33.Text; ds.Tables["re"].Rows.Add(dr); cmd.CommandText = "Select * from invoice"; cb = new SqlCommandBuilder(adp); adp.Update(ds.Tables["re"]); and error is String or binary data would be truncated.The statement has been terminated. at this line adp.Update(ds.Tables["re"]); pls help me
You have to check your input data. I think if you read a design pattern you can do this on better way. Say! your code is really horrible to understand. You have to try to use classes and generic collections if you want to manage your code. But if you check your input data, you can find the wrong input data type or data length. Good luck!!!