public partial class _Default : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("data source=.; initial catalog= Details; integrated security=sspi");
SqlDataAdapter adp1, adp2;
SqlCommandBuilder cmb;
DataSet ds, ds2;
byte[] hashValue, MessageBytes;
string StringtoConvert;
UnicodeEncoding MyUniCodeEncoding;
protected void Page_Load(object sender, EventArgs e)
{
adp1 = new SqlDataAdapter("select * from client", cn);
ds = new DataSet();
adp1.Fill(ds, "emp");
cmb = new SqlCommandBuilder(adp1);
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox9.Text = "";
StringtoConvert = TextBox3.Text;
MyUniCodeEncoding = new UnicodeEncoding();
MessageBytes = MyUniCodeEncoding.GetBytes(StringtoConvert);
SHA1Managed SHhash = new SHA1Managed();
hashValue = SHhash.ComputeHash(MessageBytes);
foreach (byte b in hashValue)
{
TextBox9.Text = TextBox9.Text + string.Format("{0:X9}", b);
}
adp2 = new SqlDataAdapter("select * from client where UserName='" + TextBox2.Text + "'", cn);
ds2 = new DataSet();
adp2.Fill(ds2, "emp");
if (ds2.Tables["emp"].Rows.Count > 0)
{
Response.Write("Username already exists, Try another username");
}
else
{
DataRow rw = ds.Tables[0].NewRow();
rw[0] = TextBox1.Text;
rw[1] = TextBox2.Text;
rw[2] = TextBox9.Text;
rw[3] = DropDownList1.Text;
rw[4] = TextBox6.Text;
rw[5] = TextBox7.Text;
ds.Tables[0].Rows.Add(rw);
adp1.Update(ds.Tables[0]);
Response.Write("Data is added");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
HyperLink1.Visible = true;
}
}
I am getting a error in this code
adp1.Update(ds.Tables[0]);
error is String or binary data would be truncated.
columns are proper and datatype is proper with appropriate range values
There is no problem in Encryption Code.
Problem occurs while entering data in database.
I am entering only very small values with are within the limit
I am not able to enter data in data base.
I find nothing wrong in the above code but still i get this error.
Any one can explain this
Regards
Amul
Stack Trace:
Line 82:
Line 83: adp1.Update(ds.Tables[0]);
Line 84: Response.Write("Data is added");
Line 85:
Source File: e:\Amul Websites\AMUL WEBSITES\ LOGIN PAGE\SignUP.aspx.cs Line: 83
Stack Trace:
[SqlException (0x80131904): String or binary data would be truncated.
The statement has been terminated.]
System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +1472823
System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +45
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +2257
System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, D