How to solve "Object reference not set to an instance of an object?

Object reference not set to an instance of an object in c#?

  • I am learning c#.net in home and learn site.my code System.Data.OleDb.OleDbConnection con; System.Data.OleDb.OleDbDataAdapter da; DataSet ds; private void Form1_Load(object sender, EventArgs e) { con = new System.Data.OleDb.OleDbConnection(); con.ConnectionString="Provider=Microsoft… Source=C:\\Users\\EJ\\Documents\\Databas… con.Open(); string sql; sql="select * from employees"; da=new System.Data.OleDb.OleDbDataAdapter(sql,c… ds=new DataSet(); da.Fill(ds,"myworkers"); con.Close(); } private void button1_Click(object sender, EventArgs e) { DataRow drow; drow = ds.Tables[0].Rows[0]; textBox1.Text=drow.ItemArray.GetValue(1)… textBox2.Text=drow.ItemArray.GetValue(2)… textBox3.Text=drow.ItemArray.GetValue(3)… } } } i am getting error object reference error in this "drow = ds.Tables[0].Rows[0];" what i have done wrong?please help me.

  • Answer:

    What that means is something in ds.Tables[0].Rows[0]; is not set (or null) So either, the dataset is not getting filled (most likely), the table is null, or rows is null. Also try DataRow drow; drow = ds.Tables["myworkers"].Rows[0];

mom at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.