Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.net code in asp

Status
Not open for further replies.

hamking01

Programmer
Joined
May 30, 2004
Messages
238
Location
US
I'm trying to set a field value of a query to a variable. This is what I have so far:

Function pkgLabel()
Dim Descr as String
Descr = Request.QueryString("Descr")
Dim sqldisplay as String
sqldisplay = "SELECT pkgInsert, pkgLabel FROM Pics WHERE " & Descr
Dim conn as OleDbConnection
conn = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\local\db\dev.mdb")
conn.Open()
Dim cmd as OleDbCommand
cmd = new OleDbCommand (sqldisplay, conn)

I'm trying to set the value of pkgInsert to variable x and pkgLabel to variable y. Thanx.
 
Code:
 sqldisplay = "SELECT pkgInsert, pkgLabel FROM Pics  WHERE " & Descr

what really happens here is you set a string not a value = string in the Where clause

you're missing something. it should look like
Code:
 sqldisplay = "SELECT pkgInsert, pkgLabel FROM Pics  WHERE descr='" & Descr & "'"

also it is not a good practice to create sql strings by concatenating the values of parameters. instead use OleDbParameter

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Dazzled,

Sorry, I was in a rush so I typed the code wrong. I meant to have the query string as in your code:
sqldisplay = "SELECT pkgInsert, pkgLabel FROM Pics WHERE descr='" & Descr & "'"

What I'm trying to get is from there I need to set x as the value of pkgInsert and y as the value of pkgLabel. From there I would need to do an If...Else statement depending on the values. I'm not sure if I would need to create and fill a dataset, or if there's something else I need to do.
 
you could use something like
Code:
Dim dt = new DataTable()
Dim oDa = new OleDbDataAdapter(cmd)
oDa.Fill(dt)

Dim x As string
Dim y As string

x = dt.Rows[0][0]
y = dt.Rows[0][1]

this code was not tested (especially since it's in vb) but has should work

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Dazzled,

This is the error I'm getting:

Value of type 'System.Data.OleDb.OleDbDataAdapter' cannot be converted to '1-dimensional array of System.Data.OleDb.OleDbDataAdapter'.

Any ideas? Thanx
 
i'm not declaring them correctly probably
Code:
Dim dt As DataTable
dt = new DataTable()
Dim oDa As OleDbDataAdapter
oDa = new OleDbDataAdapter(cmd)
oDa.Fill(dt)

Dim x As string
Dim y As string

x = dt.Rows[0][0]
y = dt.Rows[0][1]

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Ughh. Now I'm getting the following error:

BC30311: Value of type 'System.Data.DataRowCollection' cannot be converted to 'String'.

for code: x = dt.Rows[0][0]

Please help
 
Got it as follows:

Dim dt as DataTable
dt = New DataTable()
Dim da as OleDbDataAdapter
da = New OleDbDataAdapter(cmd)
da.Fill(dt)
Dim x as String
x = CType(dt.Rows(0)(0), String)
If x = "Yes
 
i told you you need to verify the code since i didn't try to compile it

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top