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
You are currently viewing the BOOK: Beginning Visual C# 2005 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
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.