By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

connecting access to C#

P: 2
I am trying to connecting Access DataBase to C#,
my data base hase 3 table.
in c# when I configure data adapter and run
Expand|Select|Wrap|Line Numbers
  1. SELECT        account.*
  2. FROM            account 
query, there is no problem and application run correctly. but when I trying to use 2 or 3 table from this data base
Expand|Select|Wrap|Line Numbers
  1. SELECT        account.ID,,, fish.bankname AS Expr2, fish.accountid, fish.fishid, bank.banknumber AS Expr3, 
  2.                          bank.bankname AS Expr1, bank.bankid AS Expr4
  3. FROM            ((account INNER JOIN
  4.                          fish ON account.ID = fish.accountid) INNER JOIN
  5.                          bank ON fish.bankname = bank.bankname) 
and when I finish this configuration and run the application and when run this line:
Expand|Select|Wrap|Line Numbers
  1. "oleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO account(name,family) VALUES ('" + nameTextBox.Text + "','" + familyTextBox.Text + "')"; "
I get below error:
"Object reference not set to an instance of an object.".

I attach my program.

Attached Files
File Type: zip (96.4 KB, 59 views)
Apr 10 '10 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 3,525
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

"How do I fix a 'object reference not set to an instance of an object' error?
The line your code stopped on while debugging holds all your answers.
One of the variables/objects was created but not initialized. For example:
Expand|Select|Wrap|Line Numbers
  1. string TempString;// Created but not initialized so this is still null
  2. //versus
  3. string TempString = string.empty;
Debug your project again. This time, when it breaks on a line look at the Locals pallet to see which variable/object is null. You can also hover your mouse over each variable and the hothelp will shows its value. One of them will be null.
Apr 10 '10 #2

P: 2
I see and I found a null object but I don't know what I do?
please see attache picture.
Attached Files
File Type: zip (89.1 KB, 49 views)
Apr 10 '10 #3

Expert 2.5K+
P: 3,525
I see and I found a null object but I don't know what I do?
Give it a value! Set it equal to something so it isn't null.

And then go to the bookstore and buy the Sam's "Learn C# in 21days" book and work through it from front to back, doing all the exercises.
Apr 11 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.