erion04 0 Newbie Poster

i don't know how to save listview items into a database i am using vb 2008 and mysql server
i have this code but unfortunately my codes aren't working
here is my code:

Dim conn As SqlConnection
conn = New SqlConnection("Data Source=VILLARINO\SQLEXPRESS;Initial Catalog=master;Integrated Security=True")
Dim a As Integer

If MsgBox("Sure you want to add this information?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
For a = 1 To ListView1.Items.Count - 1


Dim cmd2 As SqlClient.SqlCommand = New SqlCommand("INSERT INTO tblofServices(Particular,Price,DateOfTreatment, Department ) VALUES('" & ListView1.Items(a).Text & "','" & ListView1.Items(a).SubItems(1).Text & "','" & DateTimePicker1.Value.ToShortDateString & "', '" & ListView1.Items(a).SubItems(2).Text & "') WHERE Patient_no LIKE '" & txtpatientno.Text & "'", conn)

conn.Open()


Dim sdr1 As SqlClient.SqlDataReader = cmd2.ExecuteReader()


Next a
MsgBox("Data has been successfully added!")
End If
whenever i try to add an items a error occurred saying "incorrect syntax near keyword WHERE"

please help me

regards,
Erion

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.