数据库操作的ExecuteNonQuery出错...?
using System;using System.Data;
using System.Data.Odbc;
public class shiclass:System.Web.UI.Page
{
public System.Web.UI.WebControls.Label msg;
void insertdata(object obj,EventArgs ar)
{
string connstr = "Driver={Microsoft Access Driver (*.mdb)};Dbq=" + Server.MapPath("feihudata.mdb");
string sqlstr = "insert into ddd(field1,field2) values('field1aaaaaaa','field2dsdsdsdsd')";
OdbcConnection addConn = new OdbcConnection(connstr);
OdbcCommand addcom = new OdbcCommand(sqlstr,addConn);
try
{
addConn.Open();
int mynum = addcom.ExecuteNonQuery();
msg.Text = "添加成功!" + connstr;
}
catch(Exception er)
{
msg.Text = er.ToString();
}
finally
{
addConn.Close();
}
}
override protected void OnInit(EventArgs ar)
{
this.Load += new EventHandler(this.insertdata);
base.OnInit(ar);
}
}
就上面一段代码,数据库可以访问,但是用int mynum = addcom.ExecuteNonQuery();语句更新时,总出现:
System.Data.Odbc.OdbcException: ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver] 操作必须使用一个可更新的查询。 at System.Data.Odbc.OdbcConnection.HandleError(HandleRef hrHandle, SQL_HANDLE hType, RETCODE retcode) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method) at System.Data.Odbc.OdbcCommand.ExecuteNonQuery() at shiclass.insertdata(Object obj, EventArgs ar)
这样的提示错误,我想可能就是那个ststr变量SQL语句写错了吧,但是放到SQL Server的分析器里是没错的! 请大家帮帮忙,找找原因吧!