C# 先连接Access数据库,然后查询内容、更新内容,提示UPDATE语法错误,可是语句在Access中可正常执行
部分代码如下:CommandString="SELECTpasswordFROMLogInDataWHEREusername=";CommandString=String...
部分代码如下 :
CommandString = "SELECT password FROM LogInData WHERE username=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox1.Text.Trim());
DataBaseConnectionHandle = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\10.146.91.190\TeamData\TeamData.mdb");
DataBaseConnectionHandle.Open();
OleDbCommand CommandHandle = DataBaseConnectionHandle.CreateCommand();
CommandHandle.CommandText = CommandString.ToString();
OleDbDataReader DataReader = CommandHandle.ExecuteReader();
DataReader.Close();
CommandHandle.Dispose();
CommandHandle = DataBaseConnectionHandle.CreateCommand();
CommandString = "UPDATE LogInData SET password=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox2.Text.Trim());
CommandString += " WHERE username=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox1.Text.Trim());
CommandHandle.CommandText = CommandString.ToString();
CommandHandle.ExecuteNonQuery() 展开
CommandString = "SELECT password FROM LogInData WHERE username=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox1.Text.Trim());
DataBaseConnectionHandle = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\10.146.91.190\TeamData\TeamData.mdb");
DataBaseConnectionHandle.Open();
OleDbCommand CommandHandle = DataBaseConnectionHandle.CreateCommand();
CommandHandle.CommandText = CommandString.ToString();
OleDbDataReader DataReader = CommandHandle.ExecuteReader();
DataReader.Close();
CommandHandle.Dispose();
CommandHandle = DataBaseConnectionHandle.CreateCommand();
CommandString = "UPDATE LogInData SET password=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox2.Text.Trim());
CommandString += " WHERE username=";
CommandString = String.Format("{0}'{1}'", CommandString, textBox1.Text.Trim());
CommandHandle.CommandText = CommandString.ToString();
CommandHandle.ExecuteNonQuery() 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询