连接数据库出问题,麻烦看一下,谢谢!
程序在连接数据库时,如果用OleDbCommand myOleDbCommand = objconnection.CreateCommand();
myOleDbCommand.CommandText = "select * from admin where username='" + username.Text.ToString() + "'" ;
OleDbDataReader myOleDbDataReader = myOleDbCommand.ExecuteReader();
能查询出结果!但是如果用
OleDbCommand myOleDbCommand = objconnection.CreateCommand();
myOleDbCommand.CommandText = "select * from admin where username='" + username.Text.ToString() + "'" ;
OleDbCommand.ExecuteNonQuery();
检查 OleDbCommand.ExecuteNonQuery()返回值是0 什么都没有查询到!但是把myOleDbCommand.CommandText = "select * from admin where username='" + username.Text.ToString() + "'" ;换成update和delete 语句又能正常删除数据库中的数据拉, insert 语句是不能正常插入!
问题,书上说ExecuteReader()只能用于检索,而ExecuteNonQuery()可以用于,查询,插入,删除和更新,为什么
这几句程序,只能删除和更新。不能查询,插入,
谢谢!
[此贴子已经被作者于2007-3-9 11:12:16编辑过]