在 Asp.net 中更新网格视图的行时出现问题

发布于 2024-09-30 05:26:13 字数 1284 浏览 1 评论 0原文

更新网格视图的字段(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦罢 2024-10-07 05:26:13

好吧..我自己找到了原因。我使用 varchar 而不是 varchar(50)

Ok..I got the reason self. I ws using varchar instead of varchar(50)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文