本文介绍了在C#中向datagridView添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个小小的步骤,在c#中将任意选择的MDb表放到我的datagridview中。
我需要的是当我点击Add按钮时它应该在datagridview中返回一个带有空单元格的行,它应该反映在数据库中。
P.Rupesh
Hi,
I'm doing a small trail to get Any Selected MDb tables in to my datagridview in c#.
What I need is when I click on Add button it should return a row with empty cells in the datagridview and it should reflect in database.
P.Rupesh
推荐答案
Hey...
To add new row do like this....
DataSet ds = (DataSet)GV.DataSource;
DataRow dr = ds.Tables[0].NewRow();
ds.Tables[0].Rows.Add(dr);
GV.DataSource = ds;
GV.DataBind();
check it out..............:thumbsup:
DataTable dttable = new DataTable();
DataColumn column;
DataRow row;
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "Empid";
dttable.Columns.Add(column);
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "EmpName";
dttable.Columns.Add(column);
row = table.NewRow();
row["id"] = 1;
row["item"] = "Albert";
dttable.Rows.Add(row);
Gridview1.DataSource = dttable;
现在你尝试下一步更新到db。
now you try next step for update to db.
这篇关于在C#中向datagridView添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!