|
-
October 30th, 2011, 01:46 AM
#1
Database help
OK I have done something stupid, but i wanted to learn how to interface a database by using SQL, problem being that the database I'm using is MS access, I know this isn't the best db to do it with but hey, you got to be young and stupid at some point.
I have a problem where I'm getting an error saying missing field, which it is indeed missing, but i need to figure out a way to tell the db to create an auto number for that record automatically.
Is there a way to do this or do I have to search through the db to find the largest id and add 1 to it.
Code:
For example can you just write; insert into table(row,row,row) values(number.autonumber(),value,value);
Thanks
-
October 31st, 2011, 11:57 AM
#2
Re: Database help
Can you not modify the database directly to create the AutoNumber field? Is this field going to the the PK for the table or is it in addition to a PK?
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
-
October 31st, 2011, 06:25 PM
#3
Re: Database help
The database has a field which is a pk and it is an auto number, but i tried to leave out the pk value thinking it would create its own value as the others were added. Though the problem is im getting missing field, which i am assuming would be the pk field i left out from the insert statement.
-
October 31st, 2011, 11:10 PM
#4
Re: Database help
You should be able to just not include an auto-number field in your insert ...
If your table has fields ID, NAME, and AGE ... where ID was the auto-number field...
INSERT INTO [TABLE] (NAME, AGE) VALUES ('joe', 30)
This should work... good luck!
-
November 1st, 2011, 11:21 AM
#5
Re: Database help
Databases handle the population of autonumber PKs on their own without being told what the value is suposed to be. If they didn't do that, then application integration would pretty much be impossible.
If you're still having trouble, please share your SQL. As above poster dais, just don't use the PK field at all.
Code:
if (Issue.Resolved)
{
ThreadTools.Click();
MarkThreadResolved();
}
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
|
Click Here to Expand Forum to Full Width
|