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

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 works great, thanks _avd!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.