0

以下で構成されるデータベース内のテーブルを返します

  • project_id
  • タスク名
  • 始める
  • 完了
  • 位置

どういうわけか、グリッドビューからSQLにデータを挿入したい。コードを確認してください

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim SQLCmd As New SqlCommand
        SQLCmd.Connection = SQLCon

        SQLCon.open()

        ''insert data to sql database row by row
        Dim taskname, location, start, complete As String

        For i As Integer = 0 To Me.DataGridView1.Rows.Count
            taskname = Me.DataGridView1.Rows(i).Cells(0).ToString()
            start = Me.DataGridView1.Rows(i).Cells(1).ToString()
            complete = Me.DataGridView1.Rows(i).Cells(2).ToString()
            location = Me.DataGridView1.Rows(i).Cells(3).ToString()

            SQLCmd.CommandText = "insert into timeline ( project_id , taskname , start , complete , location) values (@pid,@task,@start,@complete,@location)"
            SQLCmd.Parameters.AddWithValue("@pid", TextBox1.Text)
            SQLCmd.Parameters.AddWithValue("@task", taskname)
            SQLCmd.Parameters.AddWithValue("@start", start)
            SQLCmd.Parameters.AddWithValue("@complete", complete)
            SQLCmd.Parameters.AddWithValue("@location", location)
            SQLCmd.ExecuteNonQuery()
        Next

        SQLCon.Close()
    End Sub
4

1 に答える 1