|
-
Jun 19th, 2002, 03:24 PM
#1
Thread Starter
New Member
why doesnt this work?
Dim addcards As String
Dim cardnum As Integer
Dim Peopleid As Integer
cardnum = TextBox4.Text
Peopleid = TextBox5.Text
addcards = "INSERT INTO Cards (Card_Number, People_ID) VALUES (" + cardnum + ", " + peopleid + ")"
OleDbCommand3.CommandText = addcards
but this does
Dim addcards As String
Dim cardnum As Integer
Dim Peopleid As Integer
cardnum = TextBox4.Text
Peopleid = TextBox5.Text
addcards = "INSERT INTO Cards (Card_Number, People_ID) VALUES (" + "1014" + ", " + "1528" + ")"
OleDbCommand3.CommandText = addcards
I keep getting the error of:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "INSERT INTO Cards (Card_Number, " to type 'Double' is not valid.
-
Jun 19th, 2002, 07:48 PM
#2
That's the bad habit of VB6. You cant just add a number to a string, you have to convert it first.
for the first part:
VB Code:
Dim addcards As String
Dim cardnum As Integer
Dim Peopleid As Integer
cardnum = CInt(TextBox4.Text) ' cardNum is an integer. Use the CInt() function to
' convert the string to integer.
Peopleid = CInt(TextBox5.Text) ' same here
Umm you just have to make sure that the textboxes contain numbers. You can use the Val() function too. It will only return the part of the string that contains numbers. Then you have to convert that to integer. (ie: Cint(Val(someString)) )
for the last part, you can either use the ToString method to convert your numbers to integer, or you can use the CStr() function. Also I rather use the & symbol rather than + when dealing with strings 
VB Code:
addcards = "INSERT INTO Cards (Card_Number, People_ID) VALUES (" & cardnum.ToString() & ", " + Peopleid.ToString() & ")"
HTH
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|