DataGridView分页 修改后保存到MSSQL范例
小弟初学,目前分页己完成,但在保存修改后数据时错了。求DataGridView分页 修改后保存到MSSQL范例t --------------------编程问答-------------------- DataTable dt=datagridview1.DataSource as DataTable;
dataadpter.Update(dt); --------------------编程问答-------------------- Private Sub GetData(ByVal selectCommand As String)
'Dim table As New DataTable()
Dim sqlcon As New SqlConnection()
Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
Try
Me.dataAdapter = New SqlDataAdapter(selectCommand, constr)
table.Locale = System.Globalization.CultureInfo.InvariantCulture
table.PrimaryKey = New DataColumn() {table.Columns("序号")}
Me.dataAdapter.Fill(table)
Me.BindingSource1.DataSource = table
dgvPage.SetDataGridView = Me.DataGridView1
dgvPage.RowsPerPage = 12
dgvPage.SetDataView = table.DefaultView
dgvPage.Paging()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
sqlcon.Close()
End Try
End Sub
Private Sub Submit()
Try
Me.DataGridView1.DataSource.AcceptChanges()
Me.dataAdapter.Update(CType(Me.DataGridView1.DataSource, DataTable))
MsgBox("保存数据成功", , "OP系统")
Catch ex As Exception
MsgBox("注意!保存失败!" & vbCrLf & "数据没能保存!", , "OP系统")
MessageBox.Show(ex.Message)
End Try
End Sub
保存後,數據並沒有更新 --------------------编程问答-------------------- 顶起来,大侠们可以帮忙看看错在哪吗 --------------------编程问答-------------------- 有高手在吗?能帮一下手吗? --------------------编程问答-------------------- 报的什么错,错误信息是什么样的? --------------------编程问答-------------------- 没有报错,但数据还是没有更新
Me.dataAdapter.Update(CType(Me.DataGridView1.DataSource, DataTable))
DataGridView1.DataSource单步执行时检查数据是正确的
但 BindingSource1.DataSource 的数据就是修改前的数据
数年据表有设主键
--------------------编程问答-------------------- 继续求范例,在线等 --------------------编程问答-------------------- 怎有人看,没人回 --------------------编程问答-------------------- 楼主单步调试一下呗,看看CType(Me.DataGridView1.DataSource, DataTable))中的DataTable是什么数据
补充:.NET技术 , VB.NET