"Execute" method not supported in

Posted on 2006-03-27
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 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 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
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 DID, * FROM [tblDocument]  d  LEFT JOIN [tblLocation] l on convert(varchar(50), = 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

    Expert Comment

    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

    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

    That example works fine for classic aSP, just not I'm searching for the equivalent syntax for .aspx pages. It just doesnt like the oConn."Execute method".
    LVL 5

    Expert Comment

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

    Author Comment

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

    Accepted Solution

    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.
    LVL 5

    Expert Comment

    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

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    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…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now