0
我正在使用Datagridview来显示我从2个表中加入记录。显示的数据来自其中一个表+已加入表中的数据(表3)。 SQL查询返回Datagridview中的结果(在Oracle中也能正常工作),但更新失败,因为“动态SQL生成失败。未找到基表或找到多于一个基表”。这里是我的表设计:Datagridview - Oracle更新错误“动态SQL生成失败。”
Table1:
ID_TABLE1
ITEM_NAME
ITEM_DESCRIPTION
Table3: (this is a joined view for Table1 and Table2)
ID_TABLE3
ID_TABLE1_FK
ID_TABLE3_FK
VALIDITY
DATE_CONNECTION
我的代码(完全一样,Oracle建议):
Public Class Form2
Private da As OracleDataAdapter
Private cb As OracleCommandBuilder
Private ds As DataSet
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Saving.Enabled = False 'this deals with error with updating (from Oracle site)
Dim SQL As String = "SELECT ID_TABLE1, ID_TABLE3, SERIAL_NO, ITEM_NAME, ITEM_DESCRIPTION, VALIDITY, DATE_CONNECTION from TABLE1, TABLE2 WHERE TABLE3.ID_TABLE1_FK=" & Form1.DataGridView1.CurrentRow.Cells(0).Value.ToString
Try
Oracleconn() 'connection to my DB
Dim cmd = New OracleCommand(SQL, Oracleconn)
cmd.CommandType = CommandType.Text
da = New OracleDataAdapter(cmd)
cb = New OracleCommandBuilder(da)
ds = New DataSet()
da.Fill(ds)
My_DGV.DataSource = ds.Tables(0)
Saving.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'No closing of connection here because of working with Dataset (Oracle suggestion)
End Try
End Sub
Private Sub Saving
da.Update(ds.Tables(0))
Saving.Enabled = True
End Sub
End Class
是这样,我的SQL查询错误还是什么?任何帮助将非常感激 !
P.S .:在实际情况下,只允许用户更改Table3中的“VALIDITY”列,因此我只需更新该字段。
检查是否有帮助http://stackoverflow.com/questions/1666425/using-datagridview-to-update-multiple-tables –
@phonetic_man,感谢您的链接。我的假设可能是正确的,SQL应该用JOIN构造。虽然我无法弄清楚正确的合成它:( – LuckyLuke82