使用ID保存到Oracle联接表

时间:2016-09-09 10:44:05

标签: vb.net oracle datagridview

我将表单中的数据保存到Oracle DB表中。现在我需要将数据存储在连接表中如果我的datagridview行也不是空的,但这是我被困的地方。连接表有ID_Table1_FK。这是我试过的:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Using con As OracleConnection = New OracleConnection("Data Source=MyDB;User Id=Lucky;Password=MyPassword;")
            con.Open()
            Using cmd As OracleCommand = New OracleCommand()

            cmd.CommandText = "INSERT INTO Table1(ID_Table1_PK, E_NAME, E_SURNAME, DESCRIPTION, ENTRY_DATE)
                               VALUES(MyTable_seq.nextval,: ID,: Name,: Surname,: Desc,: Entry)"

            cmd.Connection = con
            cmd.Parameters.Add(New OracleParameter("ID", TxtName.Text))
            cmd.Parameters.Add(New OracleParameter("Surname", TxtSurname.Text)
            cmd.Parameters.Add(New OracleParameter("Desc", TxtDesc.Text))
            cmd.Parameters.Add(New OracleParameter("Entry", DtpEntry.Value.ToShortTimeString))
            cmd.ExecuteNonQuery()

            End Using

            For Each row As DataGridViewRow In DataGridView1.Rows
                If row.Cells(0).Value = Nothing Then

                Else
                    Using cmd1 As New OracleCommand()

                    cmd1.CommandText = "INSERT INTO Table_Join (ID_Table1, ID_Table_Join, ADDRESS, STATE)
                                         VALUES(ID_Table1,: MyTable_seq.nextval,: address,: state)"

                    cmd1.Parameters.Add(New OracleParameter("ID_Table1", "WHAT SHOULD GO HERE??"))
                    cmd1.Parameters.Add(New OracleParameter("address", row.Cells(0).Value))
                    cmd1.Parameters.Add(New OracleParameter("state", row.Cells(1).Value))
                    cmd1.ExecuteNonQuery()

                    End Using

                End If

         End Using

     End Sub

所以基本上我需要有关如何将相同的ID值传递给另一个(连接)表的任何建议吗?

P.S。:" MyTable_seq.nextval"正在触发DB中记录的自动序列号。

0 个答案:

没有答案