返回数据库中的表包括
- 项目编号
- 任务名称
- 开始
- 完全的
- 地点
不知何故,我想将gridview中的数据插入到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