Updating a datarow in dataset
Im trying to update a data row in a data set but my program keeps on crashing at this one line, i was wandering if someone could help me out with the problem
heres the code
Code:
void updateDB()
{
for(int i=0; i < export_log.Tables[0].Rows.Count; i++)
{
export_log.Tables[0].Rows[i]["export_id"] = 9999;
dc.updateDataRow(export_log.Tables[0].Rows[i]);
}
}
public void updateDataRow(DataRow dr)
{
try
{
string table = "ExportLog";
String query = "select * from " + table;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCmd.CommandText = query;
SqlCmd.Connection = ObjConn;
SqlCommandBuilder builder = new SqlCommandBuilder(da);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
ds.Tables[table].Rows.Add(dr); // code crashes here because of null exception
da.Fill(ds);
da.Update(ds,table);
}
catch(SqlException ex)
{
Console.WriteLine("Database error");
}
}
Additional information: Object reference not set to an instance of an object.
Thats the error i get when I use the debugger.