[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


"Execute" method not supported in ASP.net

Posted on 2006-03-27
Medium Priority
Last Modified: 2012-05-05
Good morning everyone,

The following snippet of code is a classic ASP search tool that i'm trying to convert to ASP.net. The connection to the DB is a SQLClient.SQLConnection and I previously used ADODB.recordset. The code errors out because it doesnt like the "Execute" method i'm using to run my string. I know this method is not natively supported in ASP.net because it cant find the assembly required to use it. Can anyone tell me another way to execute the string in the following code? Any help would be greatly appreciated.
Thanks in advance,

<%intAdmin = Session("ADMIN")

'added for asp.net
Dim objConn as New Object
Dim objRS as New Object

    'If blnLogin = False Then Response.Redirect(("default.aspx"))
    searchtext = Request.Item("searchtext")
    searchfield = Request.Item("searchfield")
    blnSearch = False
    If Len(Trim(searchtext)) > 0 And Len(Trim(searchfield)) > 0 Then
        strSQL = "SELECT d.id DID, * FROM [tblDocument]  d  LEFT JOIN [tblLocation] l on convert(varchar(50),l.id) = d.docloc "
        Select Case searchfield
            Case "'docident'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case "'doctitle'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case "'dockeyword'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case "'docrel'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case "'docloc'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case "'docauthor'"
                strSQL = (strSQL) & "WHERE d." & searchfield & " = " & searchtext & " "
            Case Else
                strSQL = (strSQL) & "WHERE d." & searchfield & " like '%" & searchtext & "%' "
        End Select
        strSQL = strSQL & "ORDER BY d.docident, d.doctitle, d.dockeyword, d.docrel, d.docloc, d.docauthor"
        Call mf.ConnectDB()
'errors out here
        objrs = objConn.Execute(strSQL)
        blnSearch = True
    End If
Question by:snappy3273
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 16302044
I think you can do something like this, using Windows Scripting Host:

Set x = Server.CreateObject("WScript.Shell")
x.Run "c:\yourfolder\yourprogram yourparameters"

You might try it.

Good luck.


Expert Comment

ID: 16302085
This is another sample; right from the ASP.NET documentation: C:\INETPUB\iissamples\sdk\asp\database\AddDelete_JScript.asp(47)

oRs = oConn.Execute ( " Select * from authors where Author= 'Paul Enfield' and YearBorn =1967 " )

I'd imagine it will work as well with strSQL

Author Comment

ID: 16302148
That example works fine for classic aSP, just not asp.net. I'm searching for the equivalent syntax for .aspx pages. It just doesnt like the oConn."Execute method".
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 16302248
You need to use the SqlCommand object not the SqlConnection object to use the execute function.

Author Comment

ID: 16303347
Hey intreeg,
Could you possibly show me an example on how you use the SqlCommand object?
LVL 28

Accepted Solution

strickdd earned 500 total points
ID: 16305849
try this:

SqlConnection Connection = new SqlConnection(ConnectionString);
string SQL = "SELECT something FROM somewhere";
SqlCommand Command = new SqlCommand(SQL, Connection);
SqlDataReader reader;

reader = Command.ExecuteReader();

//do whatever with the reader


This will work, the whole idea of recordsets in .Net has been thrown and and readers are used. All DB connections are slightly different from language to language.

Expert Comment

ID: 16312662
If you wanted that in a table (which uses concepts closer to the old recordset style) you would then just load the reader into a datatable, for example:

//Get reader as shown above then...
DataTable myTable = new DataTable();


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question