connecting access to C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mehdi4467
    New Member
    • Apr 2010
    • 2

    connecting access to C#

    Hi,
    I am trying to connecting Access DataBase to C#,
    my data base hase 3 table.
    in c# when I configure data adapter and run
    Code:
    SELECT        account.*
    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
    Code:
    SELECT        account.ID, account.name, account.family, fish.bankname AS Expr2, fish.accountid, fish.fishid, bank.banknumber AS Expr3, 
                             bank.bankname AS Expr1, bank.bankid AS Expr4
    FROM            ((account INNER JOIN
                             fish ON account.ID = fish.accountid) INNER JOIN
                             bank ON fish.bankname = bank.bankname)
    and when I finish this configuration and run the application and when run this line:
    Code:
    "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.



    thanks
    Attached Files
    Last edited by tlhintoq; Apr 10 '10, 05:46 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    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.


    Originally posted by OriginalPoster
    "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:
    Code:
    string TempString;// Created but not initialized so this is still null
    //versus
    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.

    Comment

    • mehdi4467
      New Member
      • Apr 2010
      • 2

      #3
      thanks
      I see and I found a null object but I don't know what I do?
      please see attache picture.
      Attached Files

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        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.

        Comment

        Working...