vs2015连接数据库,*.ExecuteNonQuery();一直报错
发布网友
发布时间:2022-04-27 17:39
我来回答
共1个回答
热心网友
时间:2022-04-27 19:08
下面的代码仅供参考:
12345678910111213141516imports System.data.oledb /*引用<a href="https://www.baidu.com/s?wd=命名空间&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dhPhRknHf1PH0kP1uhuAN-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHcsnWR1PjmknWTsPHn3PjR4" target="_blank" class="-highlight">命名空间</a>*/dim cnstr = "provider=microsoft.jet.oledb.4.0,data source=Access数据库文件位置" /*定义连接字符串*/dim cn as oledbconnection = new oledbconnection(cnstr) /*定义连接*/cn.open() /*打开连接*/sqlstr="select... from... 或其他sql"dim cmd as sqlcommand=new sqlcommand()cmd.commandtext=sqlstrcmd.connection=cn/*以上是建立执行语句*/cmd.executenonquery() 不返回结果cmd.executescalar() 返回单个结果cmd.executereader() 返回结果集/*以上是执行<a href="https://www.baidu.com/s?wd=sql语句&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dhPhRknHf1PH0kP1uhuAN-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3ErHcsnWR1PjmknWTsPHn3PjR4" target="_blank" class="-highlight">s