Hey Guys,

I am now loosing my cool over this problem.
let me paste my code an then i'll explain my problem.

Here's my code :

if (rn < ds1.Tables["Company"].Rows.Count-1)
                {
                    rn = rn + 1;
                    textBox1.Text = ds1.Tables["Company"].Rows[rn].ItemArray[0].ToString();

                    SqlDataAdapter da1 = new SqlDataAdapter("Select C_ID from Company where C_NAME ='Germany'", con2);

                    da1.Fill(ds1, "Company");

Here, I have a textbox that should show the id of company that is selected by user from combo box. But somehow it keeps on nudging me error : Object reference not set to instance of an object. I tried all possible ways but couldn't find a way around.
Can anybody of you suggest anything?


thank you
Ajinkya

Recommended Answers

All 2 Replies

Which line gives you the error? The first one or the fourth?

How will dataSet show some value from it, if its empty. YOu have to retrieve the value from dataSet to textBox, after its being populated. So put the code from 4th line, bellow the line where you do the filling ("Fill()" method).

If this is not it, tell more about the problem, and tell us exactly is comes to that error.
Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.