0

我创建了一个按钮来从数据库中删除选定的行。

我的问题是删除正确的行。我想删除231标识列中包含的行,即使它位于我的数据库的第一行。

myDataSet.Tables["myTable"].Rows[**here I want to address the identity nr from column 1.**].Delete();
4

4 回答 4

0

Try this:

myDataSet.Tables["myTable"].Select("ID = 231").FirstOrDefault().Delete();

Be sure to have "using System.Linq;" at the top of the file.

于 2012-06-20T12:34:37.187 回答
0

我尝试尝试不同的解决方案,但这是我设法工作的解决方案。我是整体编程的初学者,所以可能不是最好的解决方案,但它可以满足我的要求。

SqlCeCommand myCmd = new SqlCeCommand("DELETE From myTable Where ordreID ="+myInt, myConnection); myCmd.ExecuteNonQuery();
于 2012-06-21T16:09:40.883 回答
0

尝试这个 :

string del = "DELETE From TableName Where ColumnName =@ColumnName";
        SqlDataAdapter a = new SqlDataAdapter(del, strinconnection);
        a.SelectCommand.Parameters.AddWithValue("@ColumnName", TheValue);
于 2012-06-20T12:29:07.843 回答
0

您将需要使用MSDNDataTable.Select上描述的方法来获取您需要删除的那一行。

于 2012-06-20T12:23:53.763 回答