We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


"Execute" method not supported in ASP.net

snappy3273 asked
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
Watch Question

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.

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


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".

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


Hey intreeg,
Could you possibly show me an example on how you use the SqlCommand object?
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

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();

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.