这段代码有什么问题??为什么编译能通过,但是运行就出错了???
string aaa = Request.QueryString[ "id "];
//Response.Write(aaa);
string dbname;
dbname=Server.MapPath( "lpan.mdb ");
myConnection = new OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source= " + dbname );
myConnection.Open();
myCommand = new OleDbCommand( "select lpmc,qy FROM lpan where lpmc= "+aaa+ " ", myConnection );
OleDbDataReader sr = myCommand.ExecuteReader();
while (sr.Read())
{
lpmc.Text = sr[ "lpmc "].ToString();
qy.Text = sr[ "qy "].ToString();
}
sr.Close();
myConnection.Close();
------解决方案--------------------你语句正确当然能编译通过啦.
语句正确不代表着能运行正确.
------解决方案--------------------select lpmc,qy FROM lpan where lpmc= ' "+aaa+ " ' "
------解决方案--------------------用mdb数据库得注意sql语法,并不是能在sqlserver中可以执行的语句就一定在access数据库中可以运行
------解决方案-------------------- myCommand = new OleDbCommand( "select lpmc,qy FROM lpan where lpmc= "+aaa+ " ", myConnection );
如果lpmc是数值型:
myCommand = new OleDbCommand( "select lpmc,qy FROM lpan where lpmc= "+aaa, myConnection );
如果lpmc是字符型: