C#操作ACCESS数据库时提示 “FORM子句语法错误
错误提示和代码原文如图所示
OleDbConnection oleDbConnection = new OleDbConnection();oleDbConnection.ConnectionString = string.Format(@" Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0}; Jet OLEDB:Database Password = {1}", path,"admin");OleDbCommand oleDbCommand = new OleDbCommand();oleDbCommand.Connection = oleDbConnection;mandText= "select*from [User];";oleDbConnection.Open();OleDbDataReader oleDbDataReader= oleDbCommand.ExecuteReader();if (oleDbDataReader.HasRows){while (oleDbDataReader.Read()){for (int i = 0; i < oleDbDataReader.FieldCount - 1; i++){if (!oleDbDataReader.IsDBNull(i)){listBox1.Items.Add(oleDbDataReader.GetString(i));} }} }
以上为修改后的代码可以正常查询
造成这个问题的原因是“User”是SQL的保留字增加"[ ]"号后可解除此类错误;
为自己的错误做记录
如果觉得《使用C#操作ACCESS数据库时提示 “FORM子句语法错误”。》对你有帮助,请点赞、收藏,并留下你的观点哦!