0

Database Name is ONLINEEXAM

I have several tables in the db and I want to list some table names starts with letters "set % " in Dropdownlist in asp.net.

I use the following code and I'm getting the error : invalid object name ONLINEEXAM.dbo.sysobjects

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack == false)
    {
        paperset();
    }  
}


private void paperset()
{
    try
    {
        string conn = ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString;
        SqlConnection con = new SqlConnection(conn);
        con.Open();

        SqlCommand cmd = new SqlCommand(
            "select * from ONLINEEXAM.dbo.sysobjects where name like 'Set%'", con);
        SqlDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            ListItem item = new ListItem();
            item.Value = dr[0].ToString();
            papersetlist.Items.Add(item);
        }

        dr.Close();
        con.Close();
    }
    catch (System.Exception ex) 
    { 
        MessageBox.Show(ex.Message); 
    }
    finally { }
}
2
  • try to run the query w/o db name like this select * from sysobjects where name like 'Set%' Commented Jul 27, 2012 at 18:19
  • what is your connectionstring? Commented Jul 27, 2012 at 18:21

2 Answers 2

1

May be you are running query against a different database, run you query in sql server to check it. also try this

SqlCommand cmd = new SqlCommand("select * from sys.objects where name like 'Set%'", con);

or use this to get all the tables

select * from sys.tables where name like 'Set%'
Sign up to request clarification or add additional context in comments.

Comments

0

Take a look to verify the user ID has access to the sysobjects table. Assuming you are running SQL2005 or later, you can also look at the INFORMATION_SCHEMA schema and review the TABLES view:

Select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE 
from [database.]INFORMATION_SCHEMA.TABLES

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.