Hi, I have problems deleting rows from a database table. I have read on the internet, and adjusted the code but apparently I am missing something, any help greatly appreciated. Below is the vital code that is used:
myCon.Open();
DataSet myDataSet = newDataSet();
myDataSet.Tables.Add("tbl6_MONK_LoggedIn");
SqlCommand myCommand = newSqlCommand();
myCommand.CommandType = CommandType.Text;
myCommand.CommandText = "SELECT * FROM tbl6_MONK_LoggedIn";
myCommand.Connection = myCon;
myCommand.CommandTimeout = 180;
SqlDataAdapter myAdapter = newSqlDataAdapter(myCommand);
SqlCommandBuilder cb = newSqlCommandBuilder(myAdapter);
myAdapter.Fill(myDataSet, "tbl6_MONK_LoggedIn");
for ( int i = 0; i < myDataSet.Tables["tbl6_MONK_LoggedIn"].Rows.Count; i++)
{
DataRow myRow = myDataSet.Tables["tbl6_MONK_LoggedIn"].Rows[i];
myRow.Delete();
myRow.AcceptChanges();
myDataSet.Tables["tbl6_MONK_LoggedIn"].AcceptChanges();
}
myAdapter.Update(myDataSet, "tbl6_MONK_LoggedIn");
myCon.Close();
|