Inserting Session vars has me stumped (Full Version)

All Forums >> [Web Development] >> ASP, PHP, and Database



Message


bdelahunty -> Inserting Session vars has me stumped (5/29/2009 13:11:07)

I just can't figure out what I missed in this. The insert is going to MSAccess DB, all fields are integer. Error is datatype mismatch. Appreciate any help...

<%
Function ParseBody(strText)
End Function
Dim myConnString
Dim myConnection
Dim mySQL
myConnString = Application("fedex_ConnectionString")
Set myConnection = Server.CreateObject("ADODB.Connection")
myConnection.Open myConnString

mySQL= "INSERT INTO veh_parts "
mySQL= mySQL & "(veh_id,part_name_id,part_num_id) "
mySQL= mySQL & "VALUES ('" & Session("veh_id") & "','"
mySQL= mySQL & Session("part_name_id") & "','"
mySQL= mySQL & Session("part_num_id") & "')"
myConnection.Execute mySQL
myConnection.Close
Set myConnection = Nothing
%>





ou812 -> RE: Inserting Session vars has me stumped (5/29/2009 14:59:20)

I would first insure they're integers by displaying them prior to the query, just to double check. After that, you could try casting them with cint or clng if they're longer etc.

ex:
MySQL= mySQL & "VALUES ('" & clng(Session("veh_id")) & "','"
mySQL= mySQL & clng(Session("part_name_id")) & "','"
mySQL= mySQL & clng(Session("part_num_id")) & "')"




bdelahunty -> RE: Inserting Session vars has me stumped (5/29/2009 15:56:17)

doesn't help. I thought there was a different syntax item, ' or " etc, like putting # around date variables that was missing




Spooky -> RE: Inserting Session vars has me stumped (5/29/2009 20:31:52)

Do this first and tell us what the result is :

mySQL= "INSERT INTO veh_parts " 
mySQL= mySQL & "(veh_id,part_name_id,part_num_id) " 
mySQL= mySQL & "VALUES ('" & Session("veh_id") & "','" 
mySQL= mySQL & Session("part_name_id") & "','" 
mySQL= mySQL & Session("part_num_id") & "')"

response.write mySQL
response.end

myConnection.Execute mySQL 
myConnection.Close 
Set myConnection = Nothing 


It will show what SQL you are using. Normally a data mismatch occurs when you try and put the wrong data type in a database column.

eg :
If veh_id is numeric in the DB then you use quotes like so :

mySQL= mySQL & "VALUES (" & Session("veh_id") & ",'" 






bdelahunty -> RE: Inserting Session vars has me stumped (5/30/2009 14:50:55)

Yoe were right about one of the session vars being null. fixed that and this is the response...

INSERT INTO veh_parts (veh_id,part_name_id,part_num_id) VALUES ('9','20','47')

works now.

Thanks again!!




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0625