Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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

You are currently viewing the C# 2005 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 21st, 2008, 08:23 AM
Authorized User
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Saving data in database from textbox

Hello friends,

I have a table in the database with 2 columns and also 2 textbox in the form. Whenever the user clicks the save button in the from the new row should be added in the table.
Can anybody help me.

I m using this code but its not working:


 SqlConnection con = new SqlConnection("Server='****';Database=*****");

                //open sql conection


                SqlDataAdapter ad = new SqlDataAdapter("Select * From Supplier_Master", con);
                DataSet ds = new DataSet();
                DataRow dr=new DataRow();

                dr.ItemArray[0] =textbox1.Text;
                dr.ItemArray[1] = textbox2.text;



  #2 (permalink)  
Old February 21st, 2008, 08:34 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

By default a SqlDataAdapter does not have any code to generate an insert command. Also, calling NewRow() doesn't add the row to the table.

Check out the documentation here:


Also, if you make your variable names cslightly longer it will be easier to read your code:

SqlDataAdapter adapter = new SqlDataAdapter("Select * From Supplier_Master", con);
DataSet dataset = new DataSet();
DataTable table = dataset.Tables[0];

DataRow row = table.NewRow();

row.ItemArray[0] =textbox1.Text;
row.ItemArray[1] = textbox2.text;



/- Sam Judson : Wrox Technical Editor -/

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 textbox data into Access iostream212 VB Databases Basics 0 July 20th, 2008 09:58 AM
Error for sending(saving) data to database csharpa .NET Framework 2.0 1 September 28th, 2007 03:44 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

All times are GMT -4. The time now is 12:20 PM.

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