遍历 DGV 中的列数据并插入 SQL

Loop through column data in DGV and INSERT into SQL

我目前正在使用 vb.net express 2013 在 windows 表单应用程序中工作。我有一个数据网格视图,我正在尝试遍历一列并将该列中的所有日期插入 sql数据库。出了点问题。这是我的代码:

     For cn As Integer = 0 To Datagridview.RowCount - 1
        Dim variable1 As Date = Datagridview.Rows(cn).Cells(1).Value

        'sql code
        Using conn1 As New SqlConnection(connstring)
            conn1.Open()
            Using comm1 As New SqlCommand("INSERT INTO table1 (columns) VALUES (values)", conn1)
                With comm1.Parameters
                    .AddWithValue("@Value1", variable1)
                    .AddWithValue("@Name", CBName.ValueMember)
                End With

comm1.ExecuteReader() 结束使用 conn1.Close() 结束使用 下一个

变量 1 是日期,我只是从组合框中提取名称。值和列是一组用于设置 table 的值。我的代码实际上并没有说 "columns" 和 "values"。我没有收到错误消息。它只是没有写入 sql table.

最后错过了我的执行命令.....我给家人丢脸了

最终代码有效,缺少我的执行命令,这里没什么可看的,继续。

        Try

            Using conn1 As New SqlConnection(connstring)
                conn1.Open()
                Using comm1 As New SqlCommand("INSERT INTO table1 (columns) VALUES (values)", conn1)
                    With comm1.Parameters
                        .AddWithValue("@Shear", variable1)
                        .AddWithValue("@Name", combobox)
                    End With
                    comm1.ExecuteReader()
                End Using
                conn1.Close()
            End Using

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    Next