Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Database
MS Access
Update requires a valid Insert Command
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jmcilhinney, post: 167617, member: 641"] Firstly, is there actually any reason to be calling Fill? Do you actually need to retrieve data from the database into your app? If not then don't call Fill. Just build the DataTable schema yourself or else call FillSchema to build the schema automatically based on a query without actually retrieving any data. Secondly, why would an INSERT statement be three pages long? It's going to be something as simple as:[code]INSERT INTO MyTable (Column1, Column2, Column3) VALUES (@Column1, @Column2, @Column3)[/code]You simply have to modify the column list appropriately. You don't even have to create that command yourself if you use a command builder. Is it maybe the fact that you're inserting into two related tables that is worrying you? If so then rest easy. If you do things right then that will be taken care of mostly automatically. Here's what I think you should do: 1. Learn how to use a TextFieldParser to read the data in. It's going to be far cleaner than what you've got. The MSDN Library documentation for the class includes code examples. 2. Learn how to insert data from a DataTable into a database in bulk. This thread of mine provides an example, as well as other useful ADO.NET examples: [url=http://www.vbforums.com/showthread.php?469872-Retrieving-and-Saving-Data-in-Databases]Retrieving and Saving Data in Databases[/url] 3. Learn how to create DataRelations in a DataSet. That's going to help you with inserting foreign keys into the database. This thread of mine provides an example, although the use of the relation in this case is different to yours: [url=http://www.vbforums.com/showthread.php?518065-Master-Detail-(Parent-Child)-Data-binding-(-NET-2-0-WinForms)]Master/Detail (Parent/Child) Data-binding[/url] 4. Learn how to update foreign keys in a child DataTable when inserting records from a parent DataTable. This thread of mine shows how to do that for an Access database specifically: [url=http://www.vbforums.com/showthread.php?659052-Retrieve-Access-AutoNumber-Value-After-Insert]Retrieve Access AutoNumber Value After Insert[/url] Put all that together and you can create a DataSet contain related parent and child DataTables, populate it from files and save the new data to the database. [/QUOTE]
Insert quotes…
Verification
Post reply
Database
MS Access
Update requires a valid Insert Command
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom