Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mycn As New SqlClient.SqlConnection
Dim mycom As New SqlClient.SqlCommand
mycn.ConnectionString = "Data Source=192.168.0.12;Initial Catalog=blue;uid=sa;pwd=123"
Dim i As Int32
Dim a1 As String = DataGridView1.Rows(i).Cells(0).Value.ToString
Dim a2 As String = DataGridView1.Rows(i).Cells(1).Value.ToString
mycom.CommandText = " insert into knitAM values('" & a1 & "','" & a2 & "') "
mycom.Connection = mycn
Try
mycn.Open()
For i = 0 To DataGridView1.Rows.Count
Dim mysqlreader As Data.SqlClient.SqlDataReader = mycom.ExecuteReader
mycom.ExecuteNonQuery()
Next
Catch ex As Exception
MsgBox("保存成功")
Finally
mycn.Close()
End Try
End Sub
mycom.CommandText = " insert into knitAM values('" & a1 & "','" & a2 & "') "這一句要用循環的。