Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlStr As String = "insert into tb values("
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
sqlStr &= "'" & DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(i) & "'"
If i < DataGridView1.Columns.Count - 1 Then sqlStr &= ","
Next
sqlStr &= ")"
Dim con As New SqlConnection(connectionString) '这个自己写去
con.Open()
Dim cmd As New SqlCommand(sqlStr, con)
Try
Dim result As Integer = cmd.ExecuteNonQuery()
If result > 0 Then
MsgBox "添加数据成功"
Else
MsgBox "添加数据失败"
End If
Catch (ex As Exception)
MsgBox "添加数据过程发生异常,原因:" & ex.Message
End Try
End Sub
你是不会写那个SQL语句还是不会写VB的代码?