开发者

Problem in Updating Row of a Grid View in Asp.net

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();


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜