作者darkian (darkian)
看板C_Sharp
标题[问题] 怎麽利用datagrid显示access的资料
时间Tue Sep 27 22:53:48 2011
如题…
有上网找了一些并拿来试
但就是不成功>"<
程式码如下
OleDbConnection Database_Con = null;
try
{
OleDbConnectionStringBuilder con_string =
new OleDbConnectionStringBuilder();
con_string.Provider = "Microsoft.ACE.OLEDB.12.0";
con_string.DataSource = @"setLocation.accdb";
Database_Con = new
OleDbConnection(con_string.ConnectionString);
}
catch (Exception ex)
{
Console.WriteLine("Error: Failed to Create a Database Connection." + ex.Message);
}
try
{
setLocationDataSet da = new setLocationDataSet();
OleDbCommand Select = new OleDbCommand();
Select.CommandType = System.Data.CommandType.Text;
Select.CommandText = "Select * from set1";
Select.Connection = Database_Con;
OleDbDataAdapter data = new
OlebDataAdapter(Select.CommandText,Database_Con);
data.SelectCommand = Select;
data.Fill(da,"set1");
dataGrid1.ItemsSource = da.Tables;
//Select.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error: Failed to retrieve the required
data from the DataBase.\n" + ex.Message);
}
finally
{
Database_Con.Close();
}
还有请哪位大大指点一下>"<
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 58.115.143.87
1F:→ taoko:exception写什麽? 09/28 07:16
2F:→ darkian:没出现exception,会是datagrid那边的问题吗? 09/28 08:57
3F:推 rex1224:你用dataset的时候没告诉他你要用哪张table 09/28 13:39
4F:→ rex1224:像是da.Tables[1] 09/28 13:41
5F:推 yes302:dataGrid1.ItemsSource = da.Tables <=这... 10/06 18:15