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
Related Q & A:
- How to set the C++ standard in eclipse?Best solution by stackoverflow.com
- How to Set Specific Site Collection as SharePoint Search Scope using C#?Best solution by SharePoint
- Object reference not set to an instance of an object; null?Best solution by Stack Overflow
- What is difference between instance class and static class in c#?Best solution by stackoverflow.com
- How to learn C# (moving from C++ to C#?Best solution by stackoverflow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.