hello..
my problem is, im using the following code to insert the records..but whenevr i click on ok button it shows the error "Object reference not set to an instance of an object"
im declaring the variables in the following form,
private OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= ..\\abc.mdb");
OleDbDataAdapter da;
OleDbCommand cmd;
DataSet ds;
DataRow row;
and the code on the save button is
try
{
cmd = new OleDbCommand("insert into info(name,description) values('" + txtgname.Text + "','" + txtdescription.Text + "')", cn);
//ds = new DataSet();
da = new OleDbDataAdapter(cmd);
da.InsertCommand = cmd;
da.Fill(ds, "info");
row = ds.Tables["info"].NewRow();
row["name"] = txtgname.Text;
row["description"] = txtdescription.Text;
ds.Tables[0].Rows.Add(row);
da.Update(ds.Tables[0]);
ds.AcceptChanges();
if (cn.State.ToString() == "Open")
cn.Close();
}
catch (Exception e1)
{
MessageBox.Show("Error in info " + e1.Message);
}
the database gets updated even when the error occurs.
what i need to do to stop the error.