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,
|