Ask a Question related to ASP Database, Design and Development.
-
Burt #1
name of field is in variable: how to use in SQL?
Hi,
The name of the field is in variable 'a'.
How can i use it into SQL?
This doesn't work:
<%
a="name"
set obj = Server.CreateObject("ADODB.Connection")
obj.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\db.mdb")
sql="select '" & a & "' from mytable;"
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, obj, 3, 3
....
%>
Thanks
Burt
Burt Guest
-
Iterative Insert with Variable Field Name
Hello, Someone must have come across this already, I need help with this insert query I have. I have a form that has variables as such:... -
variable named field calculated from variable named fields
I have two form fields per line defined in a cfloop thusly: <cfloop index="i" from= "1" to= "100" Step="1"> <cfif isdefined("form.item_number_"... -
Display variable in text field
Here's the code: <input type="text" name="myDate" id="myDate" value="#strDate#"> Not sure why this doesn't work. Instead of the value of the... -
Hidden field with variable problem
Here is the code: <SELECT NAME="email" style="font-family: Verdana; font-size: 10pt; " size="1"> <% DO WHILE NOT objRS.EOF strEmail =... -
Variable in the field name.
Hi All, I have one question. Usually, we can get data from table by using rst("userid") because we know the column name userid. Now, I have a... -
Bob Barrows [MVP] #2
Re: name of field is in variable: how to use in SQL?
Burt wrote:
Do a response.write sql. If a contains "thisfield", you will see this in the> Hi,
>
> The name of the field is in variable 'a'.
> How can i use it into SQL?
>
> This doesn't work:
> <%
> a="name"
> set obj = Server.CreateObject("ADODB.Connection")
> obj.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\db.mdb")
> sql="select '" & a & "' from mytable;"
browser window when you run this page:
select 'thisfield' from mytable
Open your database in Access. Create a new query using the Design View
option, switch to SQL View and paste this statement in. Run it to see what
you get. Do you see what you have to change to make it return the contents
of thisfield instead of the string 'thisfield'?
Always create and test your queries in Access before attempting to run them
in ASP.
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows [MVP] Guest
-
Burt #3
Re: name of field is in variable: how to use in SQL?
Sorry, in fact this works, but i can't recover the field values:
a="maandag"
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
=d:\access\newres.mdb")
sql="select '" & a & "' from daguur;"
set rs=Server.CreateObject("ADODB.recordset")
rs.open sql, objdc, 3, 3
response.write(rs.RecordCount) ' this works
' i tried this but none works:
z=rs.fields("'a'").value
z=rs.fields('a').value
z=rs.fields(a).value
response.write(z)
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:usgSxQheEHA.2812@tk2msftngp13.phx.gbl...the> Burt wrote:>> > Hi,
> >
> > The name of the field is in variable 'a'.
> > How can i use it into SQL?
> >
> > This doesn't work:
> > <%
> > a="name"
> > set obj = Server.CreateObject("ADODB.Connection")
> > obj.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\db.mdb")
> > sql="select '" & a & "' from mytable;"
> Do a response.write sql. If a contains "thisfield", you will see this inthem> browser window when you run this page:
>
> select 'thisfield' from mytable
>
> Open your database in Access. Create a new query using the Design View
> option, switch to SQL View and paste this statement in. Run it to see what
> you get. Do you see what you have to change to make it return the contents
> of thisfield instead of the string 'thisfield'?
>
> Always create and test your queries in Access before attempting to run> in ASP.
>
> Bob Barrows
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
Burt Guest
-
Bob Barrows [MVP] #4
Re: name of field is in variable: how to use in SQL?
Burt wrote:
You're not getting my point. Show us the result from "response.write sql"> Sorry, in fact this works, but i can't recover the field values:
>
> a="maandag"
> set objdc = Server.CreateObject("ADODB.Connection")
> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
> =d:\access\newres.mdb")
> sql="select '" & a & "' from daguur;"
Of course this works. You are getting records back. You're just not getting> set rs=Server.CreateObject("ADODB.recordset")
> rs.open sql, objdc, 3, 3
> response.write(rs.RecordCount) ' this works
records containing a field named maandag. Do this to see what you are
getting:
for each fld in rs.Fields
response.write fld.OrdinalPosition & ". " & fld.name & ": " & _
fld.value & "<BR>"
next
Did you try my suggestion of response.writing the sql variable and copying
te result into the Access Query Builder to see what the sql statement you
built returned? Obviously not. I dislike hand-holding, but just to bring
this thread to an end, change your statement to:
sql="select [" & a & "] from daguur;"
I'm out of here.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Burt #5
Re: name of field is in variable: how to use in SQL?
I appreciate your work, really, but you are not my teacher and i'm not your
student. Sometimes one needs a urgent answer and sometimes, there is no time
for experimentation.
Thanks anyway
B
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:%23jR02DieEHA.3916@TK2MSFTNGP11.phx.gbl...getting> Burt wrote:>> > Sorry, in fact this works, but i can't recover the field values:
> >
> > a="maandag"
> > set objdc = Server.CreateObject("ADODB.Connection")
> > objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
> > =d:\access\newres.mdb")
> > sql="select '" & a & "' from daguur;"
> You're not getting my point. Show us the result from "response.write sql"
>>> > set rs=Server.CreateObject("ADODB.recordset")
> > rs.open sql, objdc, 3, 3
> > response.write(rs.RecordCount) ' this works
> Of course this works. You are getting records back. You're just not> records containing a field named maandag. Do this to see what you are
> getting:
>
> for each fld in rs.Fields
> response.write fld.OrdinalPosition & ". " & fld.name & ": " & _
> fld.value & "<BR>"
> next
>
>
> Did you try my suggestion of response.writing the sql variable and copying
> te result into the Access Query Builder to see what the sql statement you
> built returned? Obviously not. I dislike hand-holding, but just to bring
> this thread to an end, change your statement to:
>
> sql="select [" & a & "] from daguur;"
>
> I'm out of here.
>
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
Burt Guest
-
Bob Lehmann #6
Re: name of field is in variable: how to use in SQL?
> but you are not my teacher and i'm not your student.
So you must be a freeloader, then. You're not paying anyone for their
assistance, so don't expect someone to do your work for you.
Following Bob's advice would have taken you less time than scolding him in a
follow-up post. You're also now assured of getting no further help at all.
Maybe you wouldn't have the need for an "urgent answer" if you were to
experiment and/or educate yourself a little.
Bob Lehmann
"Burt" <burtspam@me.us> wrote in message
news:ucp9WbieEHA.1048@tk2msftngp13.phx.gbl...your> I appreciate your work, really, but you are not my teacher and i'm nottime> student. Sometimes one needs a urgent answer and sometimes, there is nosql"> for experimentation.
> Thanks anyway
> B
>
>
>
>
>
> "Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
> news:%23jR02DieEHA.3916@TK2MSFTNGP11.phx.gbl...> > Burt wrote:> >> > > Sorry, in fact this works, but i can't recover the field values:
> > >
> > > a="maandag"
> > > set objdc = Server.CreateObject("ADODB.Connection")
> > > objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
> > > =d:\access\newres.mdb")
> > > sql="select '" & a & "' from daguur;"
> > You're not getting my point. Show us the result from "response.writecopying> getting> >> >> > > set rs=Server.CreateObject("ADODB.recordset")
> > > rs.open sql, objdc, 3, 3
> > > response.write(rs.RecordCount) ' this works
> > Of course this works. You are getting records back. You're just not> > records containing a field named maandag. Do this to see what you are
> > getting:
> >
> > for each fld in rs.Fields
> > response.write fld.OrdinalPosition & ". " & fld.name & ": " & _
> > fld.value & "<BR>"
> > next
> >
> >
> > Did you try my suggestion of response.writing the sql variable andyou> > te result into the Access Query Builder to see what the sql statement>> > built returned? Obviously not. I dislike hand-holding, but just to bring
> > this thread to an end, change your statement to:
> >
> > sql="select [" & a & "] from daguur;"
> >
> > I'm out of here.
> >
> > Bob Barrows
> >
> > --
> > Microsoft MVP -- ASP/ASP.NET
> > Please reply to the newsgroup. The email account listed in my From
> > header is my spam trap, so I don't check it very often. You will get a
> > quicker response by posting to the newsgroup.
> >
> >
>
Bob Lehmann Guest
-
Burt #7
Re: name of field is in variable: how to use in SQL?
Did somebody ask you something?
Burt Guest
-
Bob Lehmann #8
Re: name of field is in variable: how to use in SQL?
It's a public forum. I felt compelled to contribute.
"Burt" <burtspam@me.us> wrote in message
news:eyVVBWmeEHA.1644@tk2msftngp13.phx.gbl...> Did somebody ask you something?
>
>
Bob Lehmann Guest



Reply With Quote

