1

Hi, I have yet another VB question (I am a noob!). Here is my code:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Try
        Dim Equip As DataRowView = ListBox1.SelectedValue
        Dim Equip_Delete As String = Equip.DataView.ToString
        MessageBox.Show(Equip_Delete)
        cmd = New SqlCeCommand("DELETE FROM Sensor_Table WHERE Equipment_ID = @Equip", con)
        cmd.Parameters.Add(cmd.CreateParameter).ParameterName = "@Equip"
        cmd.Parameters.Item("@Equip").Value = Equip
        If con.State = ConnectionState.Closed Then con.Open()
        cmd.ExecuteNonQuery() 
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

I am trying to delete a row in my table (Sensor_Table) which is bound to ListBox1. The MessageBox is there for debugging purposes. The value shown in the message box is System.Data.DataRowView, not the selected value in ListBox1. I also get the error after the message box: No mapping exists from DbType System.Data.DataRowView to a known SqlCeType. Can someone please advise? Thanks

Edited by Thomas7399

2
Contributors
2
Replies
5
Views
4 Years
Discussion Span
Last Post by Thomas7399
1

You may use indexer method of DataRowView to obtain selected column value.

Dim Equip As DataRowView = ListBox1.SelectedValue
Dim val1=Equip(0) 'Returns value from 1st column
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.