p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   .NET Framework 2.0 (http://p2p.wrox.com/forumdisplay.php?f=141)
-   -   Error for sending(saving) data to database (http://p2p.wrox.com/showthread.php?t=54462)

csharpa February 23rd, 2007 12:09 AM

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 BindingNavigator 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 STUDENT (" +
         "S_ID, S_NAME, S_ADDRESS, S_PHONE" +
         ") VALUES ('" +
         S_IDComboBox.Text + "', '" +
         S_NAMETextBox.Text + "', '" +
         S_ADDRESSTextBox.Text + "', '" +
         S_PHONETextBox.Text + "')";

sqlDataAdapter1.InsertCommand.ExecuteNonQuery();

It gave me this error
“NulleferenceException 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_PHONE)" ,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

DARSIN September 28th, 2007 03:44 AM

can u send the error msg here... are u initalizing connection?



All times are GMT -4. The time now is 04:07 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.