0

I'm trying to copy the data from sql table "checkin " to auto fill in on a form in a textbox .. on a button click

DataSet ds = null;

private void button8_Click(object sender, EventArgs e)
{
    tblNamesBS.DataSource = ds.Tables[0];
     textBox2.DataBindings.Add(new Binding("Text", tblNamesBS,"GuestName"));
}
3
  • 1
    where do you fill ds? Commented May 31, 2013 at 12:15
  • 2
    Let me see throught my Crystal Ball and find the solution for your question. Ahhh ... wait I got it: ds is null. Commented May 31, 2013 at 12:17
  • 1
    @inxs Your Crystal Ball must be newer than mine, I can't even work out the question. Commented May 31, 2013 at 12:26

3 Answers 3

3

ds starts off as null, and you show no code that would make ds anything other than null. Thus indeed, ds.Tables[0] will explode with a NullReferenceException.

Make ds something non-null.

Sign up to request clarification or add additional context in comments.

6 Comments

thats wat i want to know how to make it non null :P
@user2430070 what have you tried? what do you want it to contain?
tblNamesBS.DataSource = ds.Tables[0] i want to put a table name "CheckIn" .. at ds.Tables[0] like dis ds.tables[CheckIn] .. but its showing an error 'Hotel_Essencia.CheckIn' is a 'type' but is used like a 'variable'
You should do a C# and .NET Tutorial first. No offense but this is a QA forum and no C# Beginner course.
@user2430070 I kinda have to agree with inxs here - there are a million and twenty "how to do data access" resources on the web; and personally I would say "the first step is: don't use DataSet"
|
2

You cant use ds before setting it to an object....

Therefore, this call is invalid ds.Tables[0]; -> You are trying to acces Tables from ds, when ds is null

Comments

0

Like the other guys said you need to instantiate ds before you can use it.

DataSet ds = new DataSet();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.