0

我的数据库中有一个表,其中有一个布尔字段。我想检查它的值并进一步使用它来删除另一个表中的记录......

虚拟代码是这样的:

private sub del_Machine()

 Dim machine_srno as string
 Dim asql As String = ("SELECT * FROM Installation_det")
 cnnOLEDB.Open()
 Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(asql, cnnOLEDB)
 Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
 If dr.Read = True Then
    if IsTFT.checked=true then      ----------> IsTFT is a column in Installation_det table
     machine_srno=Machine.value ------------> Machine is also a field in database

    DeleteQuery = "DELETE * FROM new_table WHERE sr_no=@mach_srno"
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(DeleteQuery,    cnnOLEDB)

            cmd.Parameters.AddWithValue("@mach_srno", machine_srno)
            cmd.ExecuteNonQuery()

end sub

请帮助我进行实际编码...我认为这对数据表和数据集很有帮助,但不知道如何使用它..请给我建议代码...谢谢..

4

1 回答 1

1

从 DataReader 获取值,然后将它们用于您的查询

If dr.Read = True Then
    Dim isTFT = Convert.ToBoolean(dr("IsTFT"))
    Dim machine_srno = dr("Machine").ToString()
    if isTFT = True Then
        Dim DeleteQuery = "DELETE * FROM new_table WHERE sr_no=@mach_srno"
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(DeleteQuery,    cnnOLEDB)
        cmd.Parameters.AddWithValue("@mach_srno", machine_srno)
        cmd.ExecuteNonQuery
    End If
ENd If
于 2013-04-19T07:39:43.933 回答