Datagridview 不能插入多行,每次只插入一行,请帮忙分析代码问题所在,谢谢。

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
查看全部
allbluekos
allbluekos
2015/07/04 03:45
  • datagridview
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复