我创建了一个按钮来从数据库中删除选定的行。
我的问题是删除正确的行。我想删除231
标识列中包含的行,即使它位于我的数据库的第一行。
myDataSet.Tables["myTable"].Rows[**here I want to address the identity nr from column 1.**].Delete();
我创建了一个按钮来从数据库中删除选定的行。
我的问题是删除正确的行。我想删除231
标识列中包含的行,即使它位于我的数据库的第一行。
myDataSet.Tables["myTable"].Rows[**here I want to address the identity nr from column 1.**].Delete();
Try this:
myDataSet.Tables["myTable"].Select("ID = 231").FirstOrDefault().Delete();
Be sure to have "using System.Linq;" at the top of the file.
我尝试尝试不同的解决方案,但这是我设法工作的解决方案。我是整体编程的初学者,所以可能不是最好的解决方案,但它可以满足我的要求。
SqlCeCommand myCmd = new SqlCeCommand("DELETE From myTable Where ordreID ="+myInt, myConnection); myCmd.ExecuteNonQuery();
尝试这个 :
string del = "DELETE From TableName Where ColumnName =@ColumnName";
SqlDataAdapter a = new SqlDataAdapter(del, strinconnection);
a.SelectCommand.Parameters.AddWithValue("@ColumnName", TheValue);
您将需要使用MSDNDataTable.Select
上描述的方法来获取您需要删除的那一行。