我正在开发一个asp.net Web表单并尝试将其连接到ms访问数据库。我在开始时遇到了一些问题。我们如何在Visual Studio 2010中将asp.net Web表单连接到ms访问数据库?
答案 0 :(得分:0)
您可以在此处找到正确的连接字符串:http://www.connectionstrings.com/
之后看看这段代码:
OleDbConnection con;
OleDbCommand komut;
OleDbDataReader oku;
try
{
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb");
komut = new OleDbCommand();
komut.CommandText = "select * from musteri_film order by musteri";
komut.Connection = con;
DataTable tablo = new DataTable();
tablo.Columns.Add("Müşteri");
tablo.Columns.Add("Film");
tablo.Columns.Add("Alış Tarihi");
tablo.Columns.Add("Vade Tarihi");
con.Open();
oku = komut.ExecuteReader();
DataRow satir;
while(oku.Read())
{
satir = tablo.NewRow();
satir[0] = oku[0];
satir[1] = oku[1];
satir[2] = oku[2];
satir[3] = oku[3];
tablo.Rows.Add(satir);
}
con.Close();
dataGridView1.DataSource = tablo;
}
catch(Exception)
{
con.Close();
MessageBox.Show("Oops something went totally wrong");
this.Dispose();
}
答案 1 :(得分:0)