ASP.NET 绑定数据库后如何给table赋值
public OleDbConnection ocon = null;
public OleDbCommand ocmd = null;
String reportPath = @"\Identify.accdb";
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + reportPath;
ocon = new OleDbConnection(ConStr);
ocon.Open();
String strupdate = "SELECT * FROM IdentifiedTab";
OleDbCommand myCommand = new OleDbCommand(strupdate, ocon);
myCommand.ExecuteNonQuery();
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = myCommand;
DataSet ds = new DataSet();
DataTable dt = ds.Tables[0];
ocon.Close();
上面是我的链接数据库代码。
然后下一步怎么赋值绑定table的数据呢? 麻烦具体一点 。。 另外就是这个数据绑定的代码是否可以简化一点,
------解决方案--------------------即这样:
public OleDbConnection ocon = null;
public OleDbCommand ocmd = null;
String reportPath = @"\Identify.accdb";
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + reportPath;
ocon = new OleDbConnection(ConStr);
//ocon.Open();
String strupdate = "SELECT * FROM IdentifiedTab";
OleDbCommand myCommand = new OleDbCommand(strupdate, ocon);
//myCommand.ExecuteNonQuery();
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.Fill(ds,"IdentifiedTab"); //加上这句
oda.SelectCommand = myCommand;
DataSet ds = new DataSet();
DataTable dt = ds.Tables[0];
//ocon.Close();
------解决方案--------------------public OleDbConnection ocon = null;
public OleDbCommand ocmd = null;
String reportPath = @"\Identify.accdb";
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=" + reportPath;
ocon = new OleDbConnection(ConStr);
ocon.Open();
String strupdate = "SELECT *&