导入数据包:
using System.Data.OleDb;
打开连通数据库通道:
OleDbConnection conn;
private void Form1_Load(object sender, EventArgs e)
{
//连通数据库库
string address = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=nametb.accdb";
conn = new OleDbConnection(@address);
conn.Open();
this.Text = "连接成功";
}
连接数据库三步骤:
//1.语句
string sql = "delete from goodstb where gId=" + id; //加上sql语句
//2.操作对象
OleDbCommand command = new OleDbCommand(sql, conn);
//3.执行操作
int count = command.ExecuteNonQuery();
网友评论