SQL - DataSet not filling / cannot see a table in the DB
Posted on 2003-02-24
I've done this with two other tables in my project, using similar syntax on the database, works fine. But here, my dataset doesn't seem to be filling properly. My ds.Tables["UserButtons"] is always null in the QuickWatch. I've tried changing table names, recreating the table, restarting the DB, none of which have gotten me anywhere on this problem.
I'm hoping somebody will see a stupid mistake that I couldn't find in two days. Code is below. Much thanks.
private string sUser;
//handles our database connection and data
private SqlConnection sqlConn;
private DataSet ds = new DataSet();
private SqlDataAdapter da = new SqlDataAdapter();
public UserButtonsInterface(string sUserId)
sUser = sUserId.ToUpper();
//connect to database
string sConn = "Initial Catalog=MyDatabase;Data Source=SQLSERV2;Integrated Security=SSPI;";
sqlConn = new SqlConnection(sConn);
//get the dataset with the User settings
sSql = "SELECT * FROM UserButtons WHERE UserId LIKE '"
+ sUser.ToString() + "'";
da.SelectCommand = new SqlCommand (sSql,sqlConn);
//FAILS HERE WITH "OBJECT REFERENCE NOT SET TO INSTANCE OF AN OBJECT"
int iNumRecords = ds.Tables["UserButtons"].Rows.Count;
System.Windows.Forms.MessageBox.Show("Select query found " + iNumRecords.ToString() + " rows.");