Is it true that Brother Google can't help you? I'm not sure! There are tousdend of examples:
inserting data into sql database[
^]
Ok, i will show how to do this.
1) Create new project (Windows application)
2) On the Form1:
- add ListView and change it name to: LVData2Save
- add Button and change it name to: CmdSave
3) Copy code below and paste it into module Form1 class
Remember! This example is very simple. To be more proffessional you need to change it. Read more about:
creating windows forms applications[
^]
Take a look at:
Carl Prothman site[
^]
connectionstrings site[
^]
Public Class Form1
Private Sub CmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSave.Click
Dim i As Integer = 0, retVal As Integer = 0
Dim sSQL As String = String.Empty, sConn As String = String.Empty
Dim oConn As SqlClient.SqlConnection = Nothing, oComm As SqlClient.SqlCommand = Nothing
Try
sConn = "Data Source=YourServerName;" & _
"Initial Catalog=A_TEST;Integrated Security=True"
oConn = New SqlClient.SqlConnection(sConn)
oConn.Open()
For i = 0 To Me.LVData2Save.Items.Count - 1
sSQL = "INSERT INTO [Table_1] (Field1)" & vbCr & _
"VALUES ('" & Me.LVData2Save.Items(i).Text & "')"
oComm = New SqlClient.SqlCommand(sSQL, oConn)
retVal = oComm.ExecuteNonQuery()
If retVal = 0 Then
MsgBox("Can't add this element: '" & Me.LVData2Save.Items(i).Text & "'", MsgBoxStyle.Information, "Error (row=" & i.ToString & ")")
End If
Next
Catch ex As SqlClient.SqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "SQL Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
Finally
oComm.Dispose()
oComm = Nothing
If Not oConn Is Nothing AndAlso oConn.State = ConnectionState.Open Then oConn.Close()
oConn = Nothing
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 0
With Me.LVData2Save
.View = View.Details
.Columns.Add("Data")
.Columns(0).TextAlign = HorizontalAlignment.Left
End With
For i = 1 To 10
Me.LVData2Save.Items.Add("Item " & i.ToString)
Next
End Sub
End Class