Dim sconnstring As String = "data source=(local);initial catalog=学校管理系统;integrated security=sspi"
Dim mycn As New SqlConnection
Dim mydataadapter As New SqlDataAdapter
Dim mydataset As New DataSet
Dim mysaldataset As New DataSet
Dim mytable As New DataTable
Dim mysaltable As New DataTable
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Try
With mysaltable
.Rows(0)("编号") = CStr(txtid.Text)
.Rows(0)("基本工资") = Trim(txtbasicsal.Text)
.Rows(0)("生活补贴") = Trim(txtallowance.Text)
.Rows(0)("工龄工资") = Trim(txtagesal.Text)
.Rows(0)("课时补贴") = Trim(txtteachallowance.Text)
.Rows(0)("全勤奖") = Trim(txtoutsal.Text)
End With
mycn.ConnectionString = sconnstring
mycn.Open()
Dim mygetbuilder As New SqlCommandBuilder(mydataadapter)
mydataadapter.UpdateCommand = mygetbuilder.GetUpdateCommand
mydataadapter.Update(mysaldataset, "教师工资情况表")
mycn.Close()
MsgBox("修改成功")
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End Sub
到mydataadapter.UpdateCommand = mygetbuilder.GetUpdateCommand
这条语句时就出错:
未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。
其他信息: 对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。
很郁闷