sqlAdaptor.update does Add a new row and Update an existiong row, but doesnot delete the row in Database

Monday, July 7, 2014

i am using a datagridview in a windows application which get data from MSSQL database. after making changes in grid like editing a row and adding a new row, i am updating the DB using sqlAdapter.update(dataset, tableName). Edited row and newly added row properly goes and gets stored in DB, but if i delete the row it wont.



public bool UpdateDBwithDataSet(DataSet updatedDS, string dsName)
{
try
{
Concheck();
//sAdapter = new SqlDataAdapter(SqlQuery, con);

CCDcmdBld = new SqlCommandBuilder(sAdapter);
sAdapter.DeleteCommand = CCDcmdBld.GetDeleteCommand(true);
sAdapter.UpdateCommand = CCDcmdBld.GetUpdateCommand(true);
sAdapter.InsertCommand = CCDcmdBld.GetInsertCommand(true);

if (sAdapter.Update(updatedDS, dsName) > 0)
return true;
else
return false;
}
catch (Exception ex)
{
return false;
}
finally
{
if (con.State == ConnectionState.Open) { con.Close(); }
}

}


Please let me know what the mistake am doing. (Note: it doesnot throw any exception also.)?







http://ift.tt/1rGpsKn