error for sending(saving) data to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • csharpa
    New Member
    • Feb 2007
    • 13

    error for sending(saving) data to database

    Hi,
    I’m using VS2005 and I’m trying to link the C# windows form to MSSQL. I used BindingNavigato r Control to read the data. After that I add sqlcommand and sqldataadapter to send the data to the database. My code is this

    sqlDataAdapter1 .InsertCommand. CommandText =
    "INSERT INTO SUDENT (" +
    "S_ID, S_NAME, S_ADDRESS, S_PHONE" +
    ") VALUES ('" +
    S_IDComboBox.Te xt + "', '" +
    S_NAMETextBox.T ext + "', '" +
    S_ADDRESSTextBo x.Text + "', '" +
    S_PHONETextBox. Text + "')";

    sqlDataAdapter1 .InsertCommand. ExecuteNonQuery ();

    It gave me this error
    “NulleferenceEx ception was Unhandled” and “ Object refrence not set to an instance of an object” so I add this line

    sqlCommand1 = ("INSERT INTO STUDENT (S_ID,S_NAME,S_ ADDRESS,S_PHONE ) VALUES (@S_ID,@S_NAME, @S_ADDRESS,@S_P HONE)" ,sqlConnection1 );

    Then it gave me some stupid error. By the way it didn’t make a new object of SqlCommand although I tried ….

    So can u help me to solve my problem ? Thank you
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. the only object reference I can see in your code is:
    sqlDataAdapter1
    You could check if this is the correct spelling or if indeed it exists as a valid object.

    Comment

    • csharpa
      New Member
      • Feb 2007
      • 13

      #3
      hi thank you for reply.
      i correct the spelling but it still gave me the same error.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by csharpa
        hi thank you for reply.
        i correct the spelling but it still gave me the same error.
        Interesting. You corrected the spelling to what?

        Comment

        Working...