本文介绍了如何向数据表添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我有一个gridview,可以在其rowcommand上使面板可见,并且可以从该面板更新gridview的该行的数据.
我已经使用数据读取器检索面板内文本框中的值.用户更改文本框的值.
HI all!!
I have a gridview on whose rowcommand i am making a panel visible and the from that panel i can update the data of that row of gridview.
I have used data reader to retreive values in the textbox inside the panel. User changes the values of the textboxes.
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Change")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
pnl1.Visible = true;
con.Open();
SqlCommand cmd = new SqlCommand("Select SName,SAge,SClass,SEmail from Student where ID=''" + id + "'' ", con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
txtEditAge.Text = dr.GetValue(1).ToString();
txtEditName.Text = dr.GetValue(0).ToString();
txtEditClass.Text = dr.GetValue(2).ToString();
txtEditEmail.Text = dr.GetValue(3).ToString();
HiddenField1.Value = id.ToString() ;
}
}
现在我想使用数据表做到这一点
now i want to do this using datatable
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Change")
{
int id = Convert.ToInt32(e.CommandArgument.ToString());
pnl1.Visible = true;
con.Open();
SqlCommand cmd = new SqlCommand("Select SName,SAge,SClass,SEmail from Student where ID=''" + id + "'' ", con);
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name");
dt.Columns.Add("Age", System.Type.GetType("System.Int32"));
dt.Columns.Add("Class");
dt.Columns.Add("Email");
dr = dt.NewRow();
dr[0] = ????????????????????????
}
我想在dr [0]处使用SName,在dr [1]处进行存储...请告诉我该怎么做.....
i want SName at dr[0] , SAge at dr[1]... Please tell me how to do it........
推荐答案
Hope it will help you
string queryString = "SELECT CustomerID, CompanyName FROM dbo.Customers"; SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection); DataSet customers = new DataSet();
adapter.Fill(customers, "Customers");
这篇关于如何向数据表添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!