burnt_toast
New member
- Joined
- Jul 16, 2003
- Messages
- 1
obtaining field names
Hi...
I want to be able to search an access database via keywords from an asp.net/vb.net webpage, using a server textbox object. Ive done this before using asp 3.0/vbscript, but Im just getting used to the controls (not to mention the syntax changes) of asp.net.
The way I had done it before, was to build a custom sql statement using the user input and the field names which I would obtain from the database table. However, in asp.net, I have no clue how to accomplish this task.
Here is the code that I had previously used (with asp/vbscript) to build the custom sql query:
Can anyone tell me how to obtain field names from an Access (OLEDB) database table using asp.net, or modify the above snippet so that it is more ".net friendly?"
Hi...
I want to be able to search an access database via keywords from an asp.net/vb.net webpage, using a server textbox object. Ive done this before using asp 3.0/vbscript, but Im just getting used to the controls (not to mention the syntax changes) of asp.net.
The way I had done it before, was to build a custom sql statement using the user input and the field names which I would obtain from the database table. However, in asp.net, I have no clue how to accomplish this task.
Here is the code that I had previously used (with asp/vbscript) to build the custom sql query:
Code:
set dbConnection=server.createobject("ADODB.connection")
dbConnection.connectionstring="DSN=inventory"
dbConnection.open
set dbRecordsetTemp=server.createobject("ADODB.recordset")
dataTable="Inventory"
dbRecordsetTemp.open dataTable,dbConnection,2,2,2
txtSearchString=request.form("searchparam")
qualifier=request("andor")
txtSearchString = Replace(txtSearchString,"""","")
txtSearchString = Replace(txtSearchString,"","")
txtSearchString = Replace(txtSearchString,"(","")
txtSearchString = Replace(txtSearchString,")","")
txtSearchString = Replace(txtSearchString,"_"," ")
txtSearchString=trim(txtSearchString)
if txtSearchString="" then
response.redirect(request.servervariables("http_referer"))
end if
dim dbField
strSql=""
arrSearchString=split(txtSearchString, " ")
for iLoop=lbound(arrSearchString) to ubound(arrSearchString)
strSql=strSql & "("
for each dbField in dbRecordsetTemp.fields
if dbField.type=202 then
strSql=strSql & "([" & dbField.name & "] like %" & arrSearchString(iLoop) & "%) or "
end if
next
strSql=left(strSql,len(strSql)-3)
strSql=strSql & ") " & qualifier
next
strSql=left(strSql,len(strSql)-(len(qualifier)+1))
dbRecordsetTemp.close
set dbRecordsetTemp=nothing
dbConnection.close
set dbConnection=nothing