更新GridView的问题 [英] Problem With Update GridView
本文介绍了更新GridView的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
这是我的代码更新我的GridView但无法更新记录
protected void GrdViewCont_RowUpdating( object sender,GridViewUpdateEventArgs e)
{
Label Lblid =(Label)GrdViewCont.Rows [e.RowIndex] .FindControl( LblNo< /跨度>);
TextBox txtNam =(TextBox)GrdViewCont.Rows [e.RowIndex] .FindControl( txtName跨度>);
Label Lbltp =(Label)GrdViewCont.Rows [e.RowIndex] .FindControl( LblType跨度>);
SqlCommand cmd = new SqlCommand( 更新ContarctorDefTable set Contractor_Name =' + txtNam.Text + ' +
,Contractor_Type =' + LblType.Text + 'where ID =' + Lblid.Text + < span class =code-string>',conn);
conn.Open();
SqlDataReader阅读器;
reader = cmd.ExecuteReader();
conn.Close();
GrdViewCont.EditIndex = -1;
BindGrdViewCont();
}
请帮帮我。
解决方案
用cmd替换cmd.ExecuteReader() .ExecuteNonQuery()
浏览此链接
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html [ ^ ]
为什么人们完全依赖他人。谷歌至少有1230000个结果。我们应该假设它们都不适合你吗?
https://www.google.co.in/search? q = gridview + update + asp.net& oq = gridview + update + asp.net& aqs = chrome..69i57j69i65l3j0l2.7091j0& sourceid = chrome& ie = UTF-8 [ ^ ]
你得到的错误是什么?
所以我可以来这里
Hi To All.
This is My Code To Update My GridView But Cannot Update the Record
protected void GrdViewCont_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label Lblid = (Label)GrdViewCont.Rows[e.RowIndex].FindControl("LblNo");
TextBox txtNam = (TextBox)GrdViewCont.Rows[e.RowIndex].FindControl("txtName");
Label Lbltp = (Label)GrdViewCont.Rows[e.RowIndex].FindControl("LblType");
SqlCommand cmd = new SqlCommand("update ContarctorDefTable set Contractor_Name = '" + txtNam.Text + "'" +
",Contractor_Type='" + LblType.Text + "' where ID = '" + Lblid.Text + "'", conn);
conn.Open();
SqlDataReader reader;
reader = cmd.ExecuteReader();
conn.Close();
GrdViewCont.EditIndex = -1;
BindGrdViewCont();
}
Please Help To Me.
解决方案
Replace cmd.ExecuteReader() with cmd.ExecuteNonQuery()
Go through this link
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html[^]
Why you people rely solely on others. Google has atleast 1230000 results for this. Should we assume that none of them works for you?
https://www.google.co.in/search?q=gridview+update+asp.net&oq=gridview+update+asp.net&aqs=chrome..69i57j69i65l3j0l2.7091j0&sourceid=chrome&ie=UTF-8[^]
what is the error u getting?
so tht i can chk here
这篇关于更新GridView的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文