Problem in Dataadapter, sometimes its working and sometimes its showing error pls help
-
Error "String or Binary data would be truncated. The Statement has been terminated" error on code >>>>>> public static bool SaveVisitor(string id,string n, string c, decimal p, string e,string a, string city, string country) { drow = ds.Tables[0].NewRow(); drow[0] = id; drow[1] = n; drow[2] = c; drow[3] = p; drow[4] = e; drow[5] = a; drow[6] = city; drow[7] = country; ds.Tables[0].Rows.Add(drow); vda.InsertCommand = vcb.GetInsertCommand(); int res = vda.Update(ds.Tables[0]); // showing error if (res > 0) { System.Windows.Forms.MessageBox.Show("Visitor Details Added"); return true; } else return false; }
-
Error "String or Binary data would be truncated. The Statement has been terminated" error on code >>>>>> public static bool SaveVisitor(string id,string n, string c, decimal p, string e,string a, string city, string country) { drow = ds.Tables[0].NewRow(); drow[0] = id; drow[1] = n; drow[2] = c; drow[3] = p; drow[4] = e; drow[5] = a; drow[6] = city; drow[7] = country; ds.Tables[0].Rows.Add(drow); vda.InsertCommand = vcb.GetInsertCommand(); int res = vda.Update(ds.Tables[0]); // showing error if (res > 0) { System.Windows.Forms.MessageBox.Show("Visitor Details Added"); return true; } else return false; }
amaankhan wrote:
sometimes its working and sometimes its showing error
At the time of error, trace the values going into dataset and see if something is wrong with values.
-
Error "String or Binary data would be truncated. The Statement has been terminated" error on code >>>>>> public static bool SaveVisitor(string id,string n, string c, decimal p, string e,string a, string city, string country) { drow = ds.Tables[0].NewRow(); drow[0] = id; drow[1] = n; drow[2] = c; drow[3] = p; drow[4] = e; drow[5] = a; drow[6] = city; drow[7] = country; ds.Tables[0].Rows.Add(drow); vda.InsertCommand = vcb.GetInsertCommand(); int res = vda.Update(ds.Tables[0]); // showing error if (res > 0) { System.Windows.Forms.MessageBox.Show("Visitor Details Added"); return true; } else return false; }
My guess is that the times you get the error its because "string or binary data would be truncated". Not sure why I think that though, it might have something to do with the error message. Of course, you might not understand what that error actually means, but google does[^]
-
Error "String or Binary data would be truncated. The Statement has been terminated" error on code >>>>>> public static bool SaveVisitor(string id,string n, string c, decimal p, string e,string a, string city, string country) { drow = ds.Tables[0].NewRow(); drow[0] = id; drow[1] = n; drow[2] = c; drow[3] = p; drow[4] = e; drow[5] = a; drow[6] = city; drow[7] = country; ds.Tables[0].Rows.Add(drow); vda.InsertCommand = vcb.GetInsertCommand(); int res = vda.Update(ds.Tables[0]); // showing error if (res > 0) { System.Windows.Forms.MessageBox.Show("Visitor Details Added"); return true; } else return false; }
DataAdapters are evil and should be avoided. If you want to insert some data, just insert it, it's not difficult and you'll be better off.