Hope Someone can help me....
so simply , i have 2 Table in access Database, and i wanna Insert New Record into DBChild C_Name & C_Code via my VB.Net Project. >_<
DBParent
P_ID = PK (Autonumber)
P_Name = string
P_Info = string
DBChild
P_ID = Relation / Reflection From P_ID of DBParent (So this AutoNumber too somehow)
C_ID = PK (AutoNumber)
C_Name = string
C_Code = string
*Table Relations Info (P_ID)
- Type : One To Many
- Checked : Enforce Referential Integrity
- Checked : Cascade Update Related Fields
*Note: In DBParent View mode it has dropdown/collapsible DBChild, and i can easily edit and add new record directly from there via Access database
*How it Looks in Access Database (Each Parent Item has it's own Child and it's Collapsible)
[-] P_ID | P_Name | P_Info
6 | PName6 | PInfo6
----------------------------
C_ID | C_Name | C_Code
5 | Child1 | Code1
7 | Child2 | Code2
8 |????? <- Add new row inside this P_ID /C_ID to fill C_Name & C_Code via VB?
----------------------------
[+] 7 | PName7 | PInfo7
----------------------------
*What i Prefer:
- keep DBChild - C_ID to be PK (AutoNumber) - I really needs this on my project)
- Keep P_ID = Relation / Reflection From P_ID of DBParent - Another Important Thing
- Using Conditional "WHERE" as my project needs this to compare the value with UniqeID that i mentioned below.
- God help me to find the answer, or at least Chuck Norris...
What I have tried:
I have tried this
Try
dim UniqeID = 6
DB.OpenConnection()
DB.SQLQuery = "INSERT INTO DBChild (C_Name,C_Code) VALUES (@Name,@Code) " &
"SELECT * FROM DBParent WHERE P_ID = " & UniqeID & ";"
DB.Command = New OleDbCommand(DB.SQLQuery, DB.Connection)
With DB.Command
.Parameters.AddWithValue("@Name", Txt_Snippet_Title.Text)
.Parameters.AddWithValue("@Code", Txt_Editor_Tag.Text)
.ExecuteNonQuery()
End With
MsgBox("Record Saved!.", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error " & GetCurrentMethod().Name & " !")
DB.CloseConnection()
Finally
DB.CloseConnection()
End Try
But Error Say :
Missing SemiColon (;) at end of SQL Statement
and When i try Edit/Change directly to DBChild (Both C_Name or C_Code) via VB then Error Say :
"You Cannot Add or Change a record because related record is required in table DBParent"
just Stuck by this over days (a lot surfing on internet, though) , but still can't found the answers...
Thanks in advance.
J