본문 바로가기
VB.net/DataGridView

그리드뷰 전체 DB에 업로드하는 방법

by 호야호잇 2020. 4. 2.

 Dim SqlConnnection As New SqlConnection()
        Dim cmd As New SqlCommand

        SqlConnnection.ConnectionString = dbstring
        cmd.CommandText = "Insert into TB_TWD_Phone_Img (ID, PN) Values (@ID, @PN)"
        cmd.Parameters.Add("@ID", SqlDbType.VarChar)
        cmd.Parameters.Add("@PN", SqlDbType.VarChar)

        SqlConnnection.Open()
        cmd.Connection = SqlConnnection

        For i = 0 To RadGridView1.Rows.Count - 1
            cmd.Parameters(0).Value = RadGridView1.Rows(i).Cells(0).Value
            cmd.Parameters(1).Value = RadGridView1.Rows(i).Cells(1).Value
            cmd.ExecuteNonQuery()
        Next

        cmd.Dispose()
        SqlConnnection.Close()