0

I can't find a basic error and would need some help finding it. Error comes when in my form load I am trying to display information in my textbox from my database.

  • I use the connection everywhere else so it's not the problem
  • I tried another Select statement with another table, still the same error.


what am I missing?

error is Object instance not set to reference

I know that password shouldnt be stored in a table, I am just playing around

  clsDataSource.mycon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\carole\Desktop\CollegeLasalleFall2016\ProgrammationEvenementielle\RealEstate\RealEstate.mdb");
        clsDataSource.mycon.Open();
         DataSet myset = new DataSet();
        int current = 0;

       OleDbCommand mycmd = new OleDbCommand("SELECT UserID, email, pwd, FirstName, LastName, BoolAgent, BoolAdmin FROM Users WHERE (BoolAgent = 1)", clsDataSource.mycon);
        OleDbDataAdapter myadapt = new OleDbDataAdapter(mycmd);
        myadapt.Fill(myset, "AllAgents");

      DataTable tbUser = myset.Tables["Users"];


 //fill the textbox
        txtFirstName.Text = tbUser.Rows[current]["FirstName"].ToString();
  • Most probably `tbUser` be null – sujith karivelil Dec 01 '16 at 01:38
  • I tried without tbuser so to do myset.table["Users"].Rows[current]["FirstName"].ToString(); and its still the same problem. I tried my select with another table, still the same problem. So I don't think the problem comes from the table but another small thing in the code... – NewPassionnate Dec 01 '16 at 01:40
  • Please see the marked duplicate for extensive advice on diagnosing and fixing code that throws `NullReferenceException`. If after following that advice, you are still unable to solve your problem, post a new question that includes **a good [mcve] that reliably reproduces the problem** and a clear but concise explanation of what you've done so far to diagnose the problem and what _specifically_ you are still having trouble with. See also [ask] for additional advice on how to present your question in a clear, answerable way. – Peter Duniho Dec 01 '16 at 01:40

0 Answers0