Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > BOOK: Beginning Visual C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2005
This is the forum to discuss the Wrox book Beginning Visual C# 2005 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780764578472
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 5th, 2009, 06:19 AM
Authorized User
 
Join Date: Mar 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy c# and SQL query

I am working in Asp.net c# platform. I have created a database and now by using c# I want to insert data through textboxes in the database.
The code I have written is
SqlConnection con = newSqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\\fieldstaff.mdf;Integrated Security=True;User Instance=True");
con.Open();
DataSet ds = newDataSet();
DataRow dRow = ds.Tables["dairy"].NewRow();
dRow[0] = textBox8.Text;
dRow[1] = textBox9.Text;
dRow[2] = textBox10.Text;
dRow[3] = textBox11.Text;
dRow[4] = textBox12.Text;
dRow[5] = textBox13.Text;
dRow[6] = textBox14.Text;
ds.Tables[
"dairy"].Rows.Add(dRow);
SqlDataAdapter da = newSqlDataAdapter();
da.Update(ds,
"dairy");
MessageBox.Show("1 row is added");
con.Close();

but I am getting the error "Object reference not set to an instance of an object" at "DataRow dRow = ds.Tables["dairy"].NewRow();" this point. pl. explain me the reason for the same.

Regards,
Reply With Quote
Reply


Thread Tools
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
sql query i need seearam MySQL 7 November 30th, 2008 02:14 AM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 12:49 AM
SQL Query mcinar SQL Language 2 March 1st, 2005 09:16 PM
SQL Query help ruthless Classic ASP Basics 1 December 21st, 2004 05:06 AM



All times are GMT -4. The time now is 08:22 PM.


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