Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
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

C#
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";
    }
Posted
Updated 29-Jul-15 19:59pm
v3
Comments
[no name] 29-Jul-15 18:16pm    
Your database is telling you that you do not have a table named "RegMember"
Learn to format your code
Learn to use parameters for sql commands.
BasmaSH 30-Jul-15 8:36am    
thank you

-->Go to your web config file and check the connection string is using which database
ConfigurationManager.ConnectionStrings[1].ToString()
(Instead of 1 please use a specific connection string name from your web config)
--> And then check that database have a table with the name 'RegMember' or not
 
Share this answer
 
my error ,i wrote the name of class instead of table
modification:
query = string.Format("Select * From [regtable] Where UserName='{0}' and Password='{1}' ", UserN, Pass);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900