SqlConnection myConn;

来源:百度知道 编辑:UC知道 时间:2024/05/26 01:08:54
SqlConnection myConn;
string ConnStr="server=localhost;database=bank;uid=sa;pwd=;";
string selectStr="select * from Card where cardno='"+textBox1.Text+"'and password='"+textBox2.Text+"'";
myConn=new SqlConnection(ConnStr);
myConn.Open();

SqlDataReader reader;
SqlCommand myCmd;
myCmd=new SqlCommand(selectStr,myConn);
reader=myCmd.ExecuteReader();

if(reader.Read())
{
MessageBox.Show("登录成功!");

}
else
{
MessageBox.Show("登录失败!");
}

为什么:
未处理的“System.NullReferenceException”类型的异常出现在 system.data.dll 中。

其他信息: 未将对象引用设置到对象的实例

那如何解决呢?

你引入名称空间没有?

using System.Data;
using System.Data.SqlClient;

我不知道你这个MessageBox.Show那里找来的!

你改成Response.Write好了!

如果你还有问题的话,发信息过来!

有对象没引用,CQLCOM对象你测试一下打开看看