『壹』 C# datatable 读取数据库
DataTable dtb = null;
string sql = "select class from table1 where name = '张三' ";
dtb = db.GetDataTable(db.form,sql);
string dtbStr=dtb.Rows[行下标][列下标].toString(); //两种写法,获得datatable中的某行某列专的值
string dtbStr1=dtb.Rows[行下标]["列名属"].toString();
『贰』 如何将DataTable更新到数据库中
SqlDataAdapter adapter = new SqlDataAdapter(strSql, strConn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet();
adapter.Fill(ds, "Titles");
//插入记录
DataTable table = ds.Tables["Titles"];
DataRow row = table.NewRow();
row["Title_id"] = "JP1001";
row["title"] = "programming Microsoft .NET";
row["price"] = 59.99m;
row["ytd_sales"] = 100000;
row["type"] = "business";
row["pubdate"] = new DateTime(2002, 5, 1);
table.Rows.Add(row);
//更新数据库
adapter.Update(table);