|
-
March 5th, 2003, 06:15 PM
#1
sql/vb.net problem
Whenever I try to programatically execute:
"INSERT INTO tblCampRegistrations(fldRWUID, fldRegionID, fldYear, fldRWUIDDiscount) VALUES(" & strBlah & " , " & cmbRegion.SelectedIndex + 1 & " , " & cmbYear.SelectedItem & ")"
it throws an exception, the .tostring is:
System.InvalidCastException: Cast from type 'DataRowView' to type 'String' is not valid.
at Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object Value)
at Microsoft.VisualBasic.CompilerServices.ObjectType.StrCatObj(Object vLeft, Object vRight)
at RWUDatabase.frmRegister.cmdOK_Click(Object sender, EventArgs e)
I've taken out every single SQL line that's not required and I still get this, and the datatypes all seem to be ok. Any suggestions?
-Jacob the n00b
-
March 6th, 2003, 01:17 AM
#2
I see that you want to insert 4 fields
fldRWUID,
fldRegionID,
fldYear,
fldRWUIDDiscount
But you give only 3 values
strBlah
cmbRegion.SelectedIndex + 1
cmbYear.SelectedItem
The number of fields has to match the number of values.
-
March 6th, 2003, 08:49 AM
#3
last
Observant, but not the cause of the error. Now the code is:
"INSERT INTO tblCampRegistrations(fldRWUID, fldRegionID, fldYear) " & _
"VALUES(" & strBlah & " , " & _
cmbRegion.SelectedIndex + 1 & " , " & _ cmbYear.SelectedItem & ")"
-
March 7th, 2003, 09:57 AM
#4
When specifying values in an INSERT statement, if the value is a string, you need to enclose it quotes. Also, if you are pulling values from a combobox, then you need to use the .text property to retrieve the text that is selected.
If fldRWUID is a string use quotes, if not - dont. I cant tell but your variable strBlah tells me its a string.
Try this:
Code:
Dim sSQL as string
sSQL = "INSERT INTO tblCampRegistrations (fldRWUID, fldRegionID, fldYear) " _
& "VALUES ('" & strBlah & "', " & cmbRegion.SelectedIndex + 1 _
& ", " & cmbYear.SelectedItem.Text & ")"
HTH,
Greg
-
March 7th, 2003, 10:19 AM
#5
last
Yeah that did it. I checked out what the .selectedmember actually was. I'm an idiot. I got it working last night though, thanks for all the help y'all
-Jacob
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
|