配置文件
不带密码
带密码
public static class Access
{
public static readonly string connstr = ConfigurationManager.AppSettings["connstr"].ToString();
public static DataTable Get(string sql)
{
using (OleDbConnection conn = new OleDbConnection(connstr))
{
conn.Open();
OleDbDataAdapter dbDataAdapter = new OleDbDataAdapter(sql, conn); //创建适配对象
DataTable dt = new DataTable(); //新建表对象
dbDataAdapter.Fill(dt); //用适配对象填充表对象
return dt;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string sql = "select ID from English_WORD";
DataTable dt = new DataTable();
dt= Access.Get(sql);
foreach (DataRow item in dt.Rows)
{
textBox1.Text = item[0].ToString();
}
}
原文地址:https://www.cnblogs.com/zhujie-com/p/12075768.html
时间: 2024-11-08 21:44:09