-
Insert values to an access database
I am trying to read 1000 line items from a file and put them into a Access
Database. Each line item is a seperate column. whats the best way to do this?
The way I know to insert a record to a table is by using
INSERT INTO PersonData2 VALUES (value1, value2, value3)
If I use that I a think I have to declare 1000 variables.
Is there a better way to do this. Please let me know if there is one.
-
Re: Insert values to an access database
1000 items in one table? I think some thing is wrong if so.
It all depends on how things are set up. If the 'columns' in the file exactly
match the columns in the database then just loop and build the insert statement.
Here is some quickly hacked out code. You will need to define the methods
to read next column (or do what you need) and delimit (ie 'fred') and escape
(ie 'Joe''s Bar and Grill').
StringBuffer insertStmt = new StringBuffer("INSERT INTO PersonData2 VALUES
(");
for (int i = 0; i < 1000; i++)
{
if(i > 0)
{
insertStmt.append(',');
}
insertStmt.append(DelimitAndEscape(ReadNextColumn()));
}
insertStmt.append(')');
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks