早教吧 育儿知识 作业答案 考试题库 百科 知识分享

未处理的“System.Data.OleDb.OleDbException”类型的异常出现在system.data.dll中主要代码:是在form里的usingSystem;usingSystem.Data;usingSystem.Data;usingSystem.Data.OleDb;usingSystem.Drawing;usingSystem.Collections;usingSy

题目详情
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在system.data.dll中
主要代码:是在form里的
using System;
using System.Data;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
OleDbConnection connection1 = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source =c:\\db.mdb");
string sql = "select name,password from user where name ='" + textBox1.Text + "'";
connection1.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(sql,connection1);
DataSet ds = new DataSet();
adp.Fill(ds); 就是这行代码有问题.
我try catch后的异常显示:
System.Data.OleDb.OleDbException:FROM 子句语法错误.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams,Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior,Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior,String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
▼优质解答
答案和解析
user是关键字,需要用 []转义.如:
string sql = "select name,password from [user] where name ='" + textBox1.Text + "'";
看了 未处理的“System.Da...的网友还看了以下: