本文介绍了无效的对象名称'RegMember'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击按钮登录
TB.Load(com.ExecuteReader());显示错误
无效的对象名称'RegMember'
(System.Data.SqlClient.SqlException未被用户代码处理)
代码:
when i click button login
TB.Load(com.ExecuteReader()); show error
Invalid object name 'RegMember'
(System.Data.SqlClient.SqlException was unhandled by user code)
code:
public class DB
{
SqlConnection conn;
SqlCommand com;
DataTable TB = new DataTable();
private void Initialize(CommandType CT, string DBCall)
{
conn = new SqlConnection();
com = new SqlCommand();
conn.ConnectionString = ConfigurationManager.ConnectionStrings[1].ToString();
com.CommandType = CT;
com.Connection = conn;
com.CommandText = DBCall;
conn.Open();
}
public DataTable RunQuery(string SelectQ)
{
Initialize(CommandType.Text, SelectQ);
TB = new DataTable();
TB.Load(com.ExecuteReader());
return TB;
}
RegMember.cs
RegMember.cs
public bool Login(string UserN, string Pass)
{
string query = string.Format("Select * From [RegMember] Where UserName='{0}' and Password='{1}' ", UserN, Pass);
if (db.RunQuery(query).Rows.Count == 1)
return true;
else
return false;
}
protected void Btnlogin_Click(object sender, EventArgs e)
{
RegMember member = new RegMember();
if (member.Login(TxtName.Text, TxtPasss.Text))
LblMessage.Text = "User ,Ok";
else
LblMessage.Text = "username or pass incorrect";
}
推荐答案
这篇关于无效的对象名称'RegMember'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!