这段代码有什么问题??为什么编译能通过,但是运行就出错了???
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是字符型:
myCommand = new OleDbCommand( "select lpmc,qy FROM lpan where lpmc= ' "+aaa+ " ' ", myConnection );
[解决办法]
输入字符型的数据 要用引号引上 where lpmc= ' "+aaa+ " ' "
[解决办法]
把sql语句在查询分析器里测试 看结果里是否有你想要的数据
[解决办法]
你把查出来的字段放到一个 中间变量中 再传给控件