Public Sub DataSave(ByVal TabName As String, ByVal ValueTxt() As String, ByVal Oper As Boolean)
If Oper Then 'Oper=true,修改记录;Oper=False,增加记录
CmdText = "Select * From " & TabName & " Where id=" & myId
Else
CmdText = "Select * From " & TabName
End If
Dim SQLCmd As New SqlClient.SqlCommand(CmdText, Conn) '数据库连接字符串
Dim SQLBd As New SqlCommandBuilder(SQLAdp)
Dim FieldNum As Integer '字段项数定义
Try
Conn.Open()
DataRd = SQLCmd.ExecuteReader(CommandBehavior.CloseConnection)
FieldNum = DataRd.FieldCount() '取得字段数
DataRd.Close()
Conn.Close()
Dim DTRow As DataRow = DataSet.Tables(TabName).NewRow '给缓存表增加新行
For i = 0 To FieldNum - 1
If Oper Then
DataSet.Tables(TabName).Rows(myId - 1).Item(i) = ValueTxt(i) '给缓存表指定行更新内容
Else
DTRow.Item(i) = ValueTxt(i) '给缓存表新行增加新内容
End If
Next
If Oper Then
myMsgWord = "更新"
Else
DataSet.Tables(TabName).Rows.Add(DTRow) '给TabName表增加一行新记录
myMsgWord = "增加"
End If
SQLBd.DataAdapter.Update(DataSet, TabName) '添加完毕后更新数据库
If Err.Number = 0 Then MsgBox("数据已" & myMsgWord & "!", 64, "提示!")
Catch ex As Exception
MessageBox.Show(ex.ToString, "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
End Try
End Sub
程序编写初期试验通过,可当做到第二个窗体时,总是出错。提示:对于多个基表不支持SQL生成...
怎么办,请高手指点,谢谢!