Question : Failed to convert parameter value from a ListViewItem to a String

Hi,
I have this error when I try to pass parameter value from my listbox into my query.
Please find below my VB code.
Can you help me in order to solve the porblem...
Thank you...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim con As New SqlConnection(My.Settings.MyConnectionString)
        con.Open()
        Dim cmd As New SqlCommand()
        cmd.Connection = con
        cmd.CommandTimeout = 0
        cmd.CommandType = CommandType.Text

        For Each item As ListViewItem In ListView1.CheckedItems

            cmd.Parameters.Clear()
            cmd.Parameters.Add("@param", SqlDbType.NVarChar)
            cmd.Parameters("@param").Value = item
            cmd.CommandText = "DELETE FROM SP_EXECUTION_TIMESTAMP WHERE Name = @param"
            cmd.ExecuteNonQuery()

        Next

        con.Close()
        MsgBox("OK")

    End Sub

Answer : Failed to convert parameter value from a ListViewItem to a String

If you're after the Text of the ListViewItem, you need to use its Text property....

   cmd.Parameters("@param").Value = item.Text

Wayne
Random Solutions  
 
programming4us programming4us