Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 23rd, 2007, 12:09 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old September 28th, 2007, 03:44 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: , , India.
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving data in database from textbox jainin_shah9 C# 2005 1 February 21st, 2008 08:34 AM
Error for sending(saving) data to database csharpa ADO.NET 1 March 19th, 2007 04:07 AM
error for sending(saving) data to database csharpa SQL Server 2005 0 February 22nd, 2007 10:53 AM
Error for saving data csharpa SQL Server 2005 0 February 21st, 2007 07:48 AM
Automatically Saving sending an e-mail Brendan Bartley Access 4 August 4th, 2005 05:28 AM



All times are GMT -4. The time now is 09:03 AM.


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