本文介绍了我在程序中遇到此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void txtLogin_Click(object sender, EventArgs e) {
string ConnectionString = "User ID=SYSDBA;Password=masterkey;" + "Database=localhost:C:\\Program Files\\Attend HRM\\Data\\ITAS.FDB; " + "DataSource=localhost;Charset=NONE;";
FbConnection addDetailsConnection = new FbConnection(ConnectionString);
addDetailsConnection.Open();
string SQLCommandText = "Select EMP_ID,EMP_ENO from EMP_EMP where EMP_ID= '" + txtEmpId.Text + "'";
FbDataReader dr = null;
//SqlDataReader dr = cmd.ExecuteReader();
if (!dr.Read() || dr["EMP_ENO"].ToString() != txtPassword.Text)
Response.Write("Invalid UserName&Password");
else
Response.Write("Valid-UserId=" + dr["PKUserId"]);
addDetailsConnection.Close();
}
}
我在这行出现错误.
I got an error this line.
if (!dr.Read() || dr["EMP_ENO"].ToString() != txtPassword.Text)
对象引用未设置为对象的实例.
Object reference not set to an instance of an object.
推荐答案
string ConnectionString = "Your conn string";
FbConnection addDetailsConnection = new FbConnection(ConnectionString);
addDetailsConnection.Open();
FbCommand fbCommand = new FbCommand("Your sql command string here", addDetailsConnection);
FbDataReader fbDataReader = fbCommand.ExecuteReader();
// Add your code that uses data reader...
// And add cleanup code...
fbDataReader.Close();
addDetailsConnection.Close();
FbDataReader dr = addDetailsConnection.Open;
成为
FbDataReader dr = addDetailsConnection.Open();
protected void txtLogin_Click(object sender, EventArgs e)
{
string ConnectionString = "User ID=SYSDBA;Password=masterkey;" + "Database=localhost:C:\\Program Files\\Attend HRM\\Data\\ITAS.FDB; " + "DataSource=localhost;Charset=NONE;";
SqlConnection cn = new SqlConnection(ConnectionString );
cn.Open();
string SQLCommandText = "Select EMP_ID,NAME
需要添加密码字段
from UserProfile where UsaeName= '" + txtEmpId.Text + "'";
DataTable dt= new DataTable();
sda = new SqlDataAdapter(SQLCommandText , cn);
sda.Fill(dt);
if(dt.Rows.Count >0){
if (dt.Rows[0]["PassWord"].ToString() != txtPassWord.Text)
Response.Write("Invalid UserName&Password");
else
Response.Write("Valid-UserId=" + dt.Rows[0]["EMP_ID"]);
}
con.Close();
}
}
希望有帮助,
Theingi.
Hope Be helpful,
Theingi.
这篇关于我在程序中遇到此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!