C#中提示UPDATE语法错误,求救!!!
DataSource Form2ds = new DataSource();
string addstr=null;
addstr = "Update 表名 set 字段名称='字段值' WHERE 字段名='字段值'";
Form2ds.DbConnect();\\连接数据库
Form2ds.updateDb(addstr);\\执行更新命令
以下函数在另一个类中,故用DataSource Form2ds = new DataSource();定义了变量.
public void DbConnect()
{
try
{
if (DbConn == null)
{
DbConn = new OleDbConnection();
DbConn.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\db\\ControlName.mdb;";
if (DbConn.State == ConnectionState.Closed)
{
DbConn.Open();
}
}
}
catch (Exception e)
{
MessageBox.Show("连接为失败,原因可能是", e.ToString());
}
}
public int updateDb(string sqlword)
{
OleDbCommand odc = new OleDbCommand();
odc.CommandText = sqlword;
odc.CommandType = CommandType.Text;
odc.Connection = DbConn;
if (DbConn.State == ConnectionState.Closed)
DbConn.Open();
int rowtemp = odc.ExecuteNonQuery();
DbConn.Close();
return rowtemp;
}
为什么会报UPDATE语法错误啊,各位高手,请指点啊~~
------解决方案--------------------
set 字段名称='字段值'
这个等号写成了全角的