如何实现向ACCESS数据库中插入记录
展开全部
String sql = "insert into 表名(字段1,字段2) values( '" + 字段1对应的值+ "' , '" + 字段2对应的值 + "')";
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\data.mdb";
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(sql,connection);
connection.Open();
if (cmd.ExecuteNonQuery() > 0)//判断插入数据是否成功 { //执行要操作的语句 }
String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\data.mdb";
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(sql,connection);
connection.Open();
if (cmd.ExecuteNonQuery() > 0)//判断插入数据是否成功 { //执行要操作的语句 }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |