Return the table in database consist of
- project_id
- task_name
- start
- complete
- location
somehow i wanna insert data from the gridview into sql. please check the code
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