在 Asp.net 中更新网格视图的行时出现问题
更新网格视图的字段(Varchar)时,更新的值只是文本框的第一个字符。我不明白为什么会这样??? 我也使用存储过程来更新。 请问任何人都可以告诉我这个错误的可能原因吗?
我的 C# 代码是: GridViewRow dg = gdtrng.Rows[e.RowIndex]; t1 = (TextBox)dg.Cells[2].Controls[0]; t2 = (TextBox)dg.Cells[3].Controls[0]; t3 = (TextBox)dg.Cells[4].Controls[0]; t4 = (TextBox)dg.Cells[5].Controls[0]; t5 = (TextBox)dg.Cells[6].Controls[0]; t6 = (TextBox)dg.Cells[7].Controls[0]; t7 = (TextBox)dg.Cells[8].Controls[0]; obConn.cmd.CommandType = CommandType.StoredProcedure;
obConn.cmd.CommandText = "updatetrainingschedule";
obConn.cmd.Parameters.AddWithValue("@tr_id", gdtrng.DataKeys[e.RowIndex].Value.ToString());
obConn.cmd.Parameters.AddWithValue("@tr_type", t1.Text);
obConn.cmd.Parameters.AddWithValue("@tr_subject", t2.Text);
obConn.cmd.Parameters.AddWithValue("@tr_from", Convert.ToDateTime(t3.Text));
obConn.cmd.Parameters.AddWithValue("@tr_to", Convert.ToDateTime(t4.Text));
obConn.cmd.Parameters.AddWithValue("@tr_time_from", t5.Text);
obConn.cmd.Parameters.AddWithValue("@tr_time_to", t6.Text);
obConn.cmd.Parameters.AddWithValue("@tr_venue", t7.Text);
obConn.conn.Open();
obConn.cmd.ExecuteNonQuery();
obConn.conn.Close();
While Updating a Field of a Grid View (which is Varchar) the updated value turns out to be only the the first character of the TextBox. I'm not getting why is it happening so???
Also I'm using Stored Procedure to update.
Plz can any1 tell me the probable reasons of this error??
My C# Code is :
GridViewRow dg = gdtrng.Rows[e.RowIndex];
t1 = (TextBox)dg.Cells[2].Controls[0];
t2 = (TextBox)dg.Cells[3].Controls[0];
t3 = (TextBox)dg.Cells[4].Controls[0];
t4 = (TextBox)dg.Cells[5].Controls[0];
t5 = (TextBox)dg.Cells[6].Controls[0];
t6 = (TextBox)dg.Cells[7].Controls[0];
t7 = (TextBox)dg.Cells[8].Controls[0];
obConn.cmd.CommandType = CommandType.StoredProcedure;
obConn.cmd.CommandText = "updatetrainingschedule";
obConn.cmd.Parameters.AddWithValue("@tr_id", gdtrng.DataKeys[e.RowIndex].Value.ToString());
obConn.cmd.Parameters.AddWithValue("@tr_type", t1.Text);
obConn.cmd.Parameters.AddWithValue("@tr_subject", t2.Text);
obConn.cmd.Parameters.AddWithValue("@tr_from", Convert.ToDateTime(t3.Text));
obConn.cmd.Parameters.AddWithValue("@tr_to", Convert.ToDateTime(t4.Text));
obConn.cmd.Parameters.AddWithValue("@tr_time_from", t5.Text);
obConn.cmd.Parameters.AddWithValue("@tr_time_to", t6.Text);
obConn.cmd.Parameters.AddWithValue("@tr_venue", t7.Text);
obConn.conn.Open();
obConn.cmd.ExecuteNonQuery();
obConn.conn.Close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧..我自己找到了原因。我使用 varchar 而不是 varchar(50)
Ok..I got the reason self. I ws using varchar instead of varchar(50)
看这两个链接
http://www. c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/
http://www.codeproject.com /Articles/417693/Insert-Update-Delete-in-ASP-NET-Gridview-DataSourc
,您可以在其中获取带有演示屏幕的代码示例
See this two link
http://www.c-sharpcorner.com/UploadFile/9f0ae2/gridview-edit-delete-and-update-in-Asp-Net/
http://www.codeproject.com/Articles/417693/Insert-Update-Delete-in-ASP-NET-Gridview-DataSourc
where you get code sample with demo screen