Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO Access problem

Status
Not open for further replies.

infacta

Programmer
Feb 10, 2003
12
IE
Hi All,
I have a problem when trying to insert rows into a microsoft Access database. I know the problem is due to a parent/child relationship. The problem is i can't seem to find the correct syntax to access(insert into) the child.
Will the INSERT INTO command still work??
If so, how do i specifiy the ParentID??
Thanks all,
Infacta
 
are you sure you are in the correct forum?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Christiaan,
I believe this is a VB.NET forum.
I am trying to access the database through VB.NET. I have seen some similiar database accessing questions in this forum so i hope and believe i am in the correct forum
 
As to what I can understand your question relates to the correct syntax of the insert statement, wich is an access command so therefor I assume you are in the wrong forum.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Can you post some snippets of code of what you are trying to do?

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
I see what you are saying. Maybe i didn't explain myself properly.
The Syntax i already know. INSERT INTO is already defined in Access.
What i am looking for is a VB.NET work around for the parent/child issue since i cannot find anyway way to perform this directly using JET or ADODB

 
The Following is a section of code adding just 1 piece of information. This should work, and indeed does with a new clean database. However in my case, the table 'Project' is related back to another table via the 'Name' parameter.

Dim MyConnectionName As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\TESTData.mdb"
Dim MyConnection As New OleDb.OleDbConnection(MyConnectionName)
MyConnection.Open()
Dim mySelectQuery As New OleDb.OleDbCommand
mySelectQuery.CommandText = "INSERT INTO Project (Name) VALUES ('Infacta') "
Try
mySelectQuery.ExecuteNonQuery()
Catch ex As Exception
End Try
MyConnection.Close()

As a result i get errors when trying to run this.
errors look like
'System.Data.OleDb.OleDbException' you cannot add or change a record because a related record is required in table 'User_'.
I am puzzled as to how to get around the problem
Any help would be appreciated, even prompts to another forum or post if it'll help.

cheers,
Infacta

 
This a referential integrity problem, or not a problem more like a protection. you need to add this record to the user table before adding it to the project table.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Hi All,
I have figured out the problem.
In the end it turned out that the database i was using has a different relational structure than i first thought. I was referencing incorrect ID's.
As suspected, the 'INSERT INTO' command does indeed work.
I thank you for all your efforts and comments and apologise for wasting anyone's time


cheers,
Infacta

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top