Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: SQL Data Missmatch


Message #1 by "Nadia Hamza" <hamzan@h...> on Thu, 23 Nov 2000 20:48:56 -0000
Hi,



I'm having trouble with the following code:



        conference = CStr(Request.Form("Conference"))



	Set objRec = Nothing

	Set objRec = Server.CreateObject ("ADODB.Recordset")



    sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions

WHERE Conference = " & conference & ";"



    objRec.Open sql, strConnect, adOpenStatic, adLockReadOnly, adCmdText 



I get a Data missmatch error with Conference = " & conference & ";" of the

query string.  I can put conference='333' and it works but I need it to be

able to pick up the variable from my form. If I try Conference = ' &

conference & ';" I get another error and it doesn't pick up the maxnum.



Any help would be greatly appreciated.



Nadia 

Message #2 by Robert Chartier <rchartierh@a...> on Thu, 23 Nov 2000 16:14:56 -0500
  conference = CStr(Request.Form("Conference"))



indicates that conference is a string, thus you will need to use qualifiers 

in your sql:





WHERE Conference = '" & conference & "';"



notice the apostrophe's around the string conference,





also consider

http://www.aspalliance.com/nothingmn/view.asp?aid=22



and how it effects you







\At 03:48 PM 11/23/00, you wrote:

>Hi,

>

>I'm having trouble with the following code:



>

>         conference = CStr(Request.Form("Conference"))

>

>         Set objRec = Nothing

>         Set objRec = Server.CreateObject ("ADODB.Recordset")

>

>     sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions

>WHERE Conference = " & conference & ";"

>

>     objRec.Open sql, strConnect, adOpenStatic, adLockReadOnly, adCmdText

>

>I get a Data missmatch error with Conference = " & conference & ";" of the

>query string.  I can put conference='333' and it works but I need it to be

>able to pick up the variable from my form. If I try Conference = ' &

>conference & ';" I get another error and it doesn't pick up the maxnum.

>

>Any help would be greatly appreciated.

>

>Nadia

>



Robert Chartier

Author, AspFree.com

xxx-xxx-xxxx

rchartierh@a...

http://www.aspfree.com/devlinks

http://www.aspfree.com/authors/robert

http://www.aspalliance.com/nothingmn



Message #3 by "Dallas Martin" <dmartin@z...> on Thu, 23 Nov 2000 16:21:04 -0500
Nadia,



You need to place the "conference" variable within quotes.

As in > WHERE Conference = ' " & conference & "' ;"





----- Original Message -----

From: "Nadia Hamza" <hamzan@h...>

To: "ASP Databases" <asp_databases@p...>

Sent: Thursday, November 23, 2000 3:48 PM

Subject: [asp_databases] SQL Data Missmatch





> Hi,

>

> I'm having trouble with the following code:

>

>         conference = CStr(Request.Form("Conference"))

>

> Set objRec = Nothing

> Set objRec = Server.CreateObject ("ADODB.Recordset")

>

>     sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions

> WHERE Conference = " & conference & ";"

>

>     objRec.Open sql, strConnect, adOpenStatic, adLockReadOnly, adCmdText

>

> I get a Data missmatch error with Conference = " & conference & ";" of the

> query string.  I can put conference='333' and it works but I need it to be

> able to pick up the variable from my form. If I try Conference = ' &

> conference & ';" I get another error and it doesn't pick up the maxnum.

>

> Any help would be greatly appreciated.

>

> Nadia

>

Message #4 by ckoski@w... on Thu, 23 Nov 2000 16:24:54 -0500
hey Nadia,





try this:



sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions WHERE

Conference ='" & conference & "';"





notice the " ' " just before the double quotation and just after...  you

forgot them in your SQL statement... any time you have a non-numeric field

in your database, you need to surround the value in the SQL statement with '

on either side...



the best way to debug SQL statements is to do this type of thing in your

code:



conference = CStr(Request.Form("Conference"))



Set objRec = Nothing

Set objRec = Server.CreateObject ("ADODB.Recordset")



sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions WHERE

Conference = " & conference & ";"



' insert this line here

' --------

Response.write sql

' --------



objRec.Open sql, strConnect, adOpenStatic, adLockReadOnly, adCmdText





This will print the SQL string you are passing to the ADO object... and you

can debug a lot more quickly while you are still getting comfortable with

ADO and SQL in ASP...



Good luck!



Cory



----- Original Message -----

From: "Nadia Hamza" <hamzan@h...>

To: "ASP Databases" <asp_databases@p...>

Sent: Thursday, November 23, 2000 3:48 PM

Subject: [asp_databases] SQL Data Missmatch





> Hi,

>

> I'm having trouble with the following code:

>

>         conference = CStr(Request.Form("Conference"))

>

> Set objRec = Nothing

> Set objRec = Server.CreateObject ("ADODB.Recordset")

>

>     sql = "SELECT Max(SpecialSessionIdentifier) AS maxnum FROM qSessions

> WHERE Conference = " & conference & ";"

>

>     objRec.Open sql, strConnect, adOpenStatic, adLockReadOnly, adCmdText

>

> I get a Data missmatch error with Conference = " & conference & ";" of the

> query string.  I can put conference='333' and it works but I need it to be

> able to pick up the variable from my form. If I try Conference = ' &

> conference & ';" I get another error and it doesn't pick up the maxnum.

>

> Any help would be greatly appreciated.

>

> Nadia

>




  Return to Index