Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Passing Date and Text Variable to a SQL Statement


Message #1 by pritesh_b@t... on Mon, 26 Mar 2001 17:19:14
Hi All,



I am trying to pass two variables from a Dropdown List to a SQL statement.



The drop down side is fine but how should I create the second page here is 

some of my code:



<%



dim oConn

dim oRS

dim strSource



set oConn=server.createobject("ADODB.Connection")

set oRS=server.createobject("ADODB.Recordset")

strSource = "DRIVER={Microsoft Access Driver (*.mdb)}"

strSource = strSource & "; DBQ=\\web\Inetpub\wwwroot\data\web.mdb"



oConn.ConnectionString = strSource



mainSQL="SELECT tblSupportSched.DATE, tblProductName.ProductName etc... 

WHERE tblSupportSched.DATE=#1/29/00# AND tblProductName.ProductName ='XyZ'"



%>



<% TABLE TO SHOW OUTPUT %>



The two variables I would like to pass are :



DATE and ProductName 



As a test i am putting static information at the moment ie



dim DateEnt

dim Product

set DateEnt = '#1/29/00#'

set Product = "XyZ"'



mainSQL="SELECT tblSupportSched.DATE, tblProductName.ProductName etc... 

WHERE tblSupportSched.DATE=& Date & AND tblProductName.ProductName ='& 

Product &'"



This does not work...



Any help would be appreciated.



Thanks



Kind Regards,



Pritesh



Message #2 by "Markus Hain" <kill@g...> on Wed, 28 Mar 2001 12:42:55
> Hi All,

> 

> I am trying to pass two variables from a Dropdown List to a SQL 

statement.

> 

> The drop down side is fine but how should I create the second page here 

is 

> some of my code:

> 

> <%

> 

> dim oConn

> dim oRS

> dim strSource

> 

> set oConn=server.createobject("ADODB.Connection")

> set oRS=server.createobject("ADODB.Recordset")

> strSource = "DRIVER={Microsoft Access Driver (*.mdb)}"

> strSource = strSource & "; DBQ=\\web\Inetpub\wwwroot\data\web.mdb"

> 

> oConn.ConnectionString = strSource

> 

> mainSQL="SELECT tblSupportSched.DATE, tblProductName.ProductName etc... 

> WHERE tblSupportSched.DATE=#1/29/00# AND tblProductName.ProductName 

='XyZ'"

> 

> %>

> 

> <% TABLE TO SHOW OUTPUT %>

> 

> The two variables I would like to pass are :

> 

> DATE and ProductName 

> 

> As a test i am putting static information at the moment ie

> 

> dim DateEnt

> dim Product

> set DateEnt = '#1/29/00#'

> set Product = "XyZ"'

> 

> mainSQL="SELECT tblSupportSched.DATE, tblProductName.ProductName etc... 

> WHERE tblSupportSched.DATE=& Date & AND tblProductName.ProductName ='& 

> Product &'"

> 

> This does not work...

> 

> Any help would be appreciated.

> 

> Thanks

> 

> Kind Regards,

> 

> Pritesh

> 

Hi



There could be two things wrong here. You need to pass these variables as 

strings to your database, to test your sql statement use query analyzer or 

something and use the same sql statement to see what is wrong. The second 

thing could be that your db expects the date in mm/dd/yyyy format, or 

another format other than used in your code. Why don't you use 

response.write to see how the insert is passed to your db ?



Regards



Markus

  Return to Index