boolean values in an insert problem
I try to use this command:
Code:
Dim strSQL As String = "insert into Auto values('" & strVIN & "','" & strMake & "','" & strModel & "'," & intCatID & ",'" & strAutoYear & "'," & Math.Round(decAutoCost, 2).ToString & ",'" & RegExp.ToString & "'," & intISMiles & ",'" & ISDate.ToString & "','" & strStall & "'," & intCurrentMiles.ToString & "," & blnMntFlag.ToString & "," & blnDamageFlag.ToString & "," & blnRentable.ToString & ")"
which in this case builds this statement:
"insert into Auto values('A73jF72jhnf7','Yugo','Pimpmobile',5,'1977',100.00,'12/22/2006 4:08:23 PM',0,'12/5/2006 12:00:00 AM','A1',250000,False,False,True)"
and get this error:
The name "False" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
I could have sworn it took it in that form another time I did this. The table structure is in that order except the first column is, of course, the primary key which is an index so I left that out. It it getting confused and trying to put things in in the wrong order because of that? If so, how do I fix that. I totally need to fix it fast cuz I told myself I won't turn off this song on a loop until I fix this part of the project and it's Remind Me by Royksopp (from the Geico Airport Commercial) and it's gotta go real soon lol.
P.S. I'm using Microsoft SQL server and the last three column specs are bit
Re: boolean values in an insert problem
You should always specify the fieldnames, eg:
Code:
insert into Auto (field1, field2, ... fieldn) values('A73jF72jhnf7', ...
Re: boolean values in an insert problem
But I don't wanna! :P oh and I forgot to post back, just for the fun of it I using CINT() instead of tostring in case it wanted a 0 or 1 and whadda you know, it did :( even DB2 can figure out that an insert doesn't include the index and nudges the rest over so I never do that for anything without paramters and datatables really. It's soooooo stupid of them to have let you input (if fact, ONLY let you input) True or False in the show table data area in visual studio and ONLY take 0 or 1 from within your program. That's just bad :mad: :eek2:
Re: boolean values in an insert problem
What database are you using?
You can get round this, by using a stored procedure to perform the insert (provided of course the database allows this), and pass in parameters. Then you can pass in true / false and the stored procedure will translate to the relevant value.
Re: boolean values in an insert problem
As an aside, back in 1990, myself and some colleagues were working on IBM 3090's. The company I worked with had 6 of them, and for disaster recovery purposes, they placed them in different sites. We were learning assembly programming, and one of my friends completed their program, it compiled and we ran it.
Somehow or another the program caused the mainframe to shut down, but being in a clustered environment, the other mainframes took over and one by one they all shut themselves down. It made for a very interesting day that day.
Seeing your picture reminded me of this.