Harabati
Harabati

Reputation: 133

Get the values of a column and use it to delete a record in database

I have a table in my database where i have a boolean field. I want to check its value and use it further for deleting record in another table...

Dummy Code is like this:

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

Please help me for actual coding... I think it will be help ful wit data table and data set but dont know how exactly to use it.. please suggest me with code... Thank You..

Upvotes: 0

Views: 919

Answers (1)

Steve
Steve

Reputation: 216273

Get the values from the DataReader and then use them for your query

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

Upvotes: 1

Related Questions