none
Using IAsync with OdbcCommand RRS feed

  • Question

  • Hi, i am currently having a problem with IAsync and odbcCommand. Is it possible to use IAsyncResult with odbcCommand as i need it for multiple SQL queries.

     

    The code that i use is as below 

    Code Snippet

    OdbcCommand inventoryCommand = new OdbcCommand(inventoryQuery, inventoryConnection);

    IAsyncResult arInventory = inventoryCommand.ExecuteReader();

     

    The error i get is:

    Cannot implicitly convert type 'System.Data.Odbc.OdbcDataReader' to 'System.IAsyncResult'

     

    Can someone help me with this problem? Any help is appreciated. Thank you.

    Monday, June 4, 2007 3:38 AM

All replies

  • You could create a delegate with the same signature, and then call the generated BeginInvoke to get access to the AsyncCallback (and it's AsyncWaitHandle)...


    Code Snippet

    delegate OdbcDataReader AsyncReader();

    OdbcCommand cmd = null;
    IAsyncResult result = new AsyncReader( cmd.ExecuteReader ).BeginInvoke( null, null );
    // do something with result.AsyncWaitHandle;



    Monday, June 4, 2007 6:07 AM
  • Thanks for your reply timvw, do u mind explaining a bit about the code that you have written? I gt an error when i placed the code inside the Button_Click.

     

    The code is as below. 

    Code Snippet

    protected void Button1_Click(object sender, EventArgs e)

    {

    string inventory = WebConfigurationManager.ConnectionStrings["rockwellConnectionString"].ConnectionString;

    using (OdbcConnection inventoryConnection = new OdbcConnection(inventory))

    {

    string inventorySearch = search.Text;

    inventoryConnection.Open();

    string inventoryQuery = "Select Part_number, imageUrl, drawingUrl, Description, Total_Quantity, On_Order, Quantity_In_Stock, Vendor_Name, Category_Name from vendor, logix_asset_list, logix_asset_list_category where logix_asset_list.logix_asset_list_category_id = logic_asset_list_category.logix_asset_list_category_id and logix_asset_list.Vendor_ID = vendor.Vendor_ID and Part_Number Like '%"+@inventorySearch+"%'";

    OdbcCommand inventoryCommand = new OdbcCommand(inventoryQuery,inventoryConnection);

    inventoryCommand.CommandType = CommandType.Text;

    inventoryCommand.Parameters.Add("@inventorySearch", OdbcType.Text).Value = inventorySearch;

    delegate OdbcDataReader AsyncDataReader();

    OdbcCommand cmd = null;

    IAsyncResult arInventory = new AsyncDataReader(cmd.ExecuteReader).BeginInvoke(null,null);

    }

    }

     

    The error message is: } expected 

                                           Type or namespace definition, or end-of-file expected

    Monday, June 4, 2007 6:48 AM
  • Thanks for your reply timvw, do u mind explaining a bit about the code that you have written? I gt an error when i placed the code inside the Button_Click.

     

    The code is as below. 

    Code Snippet

    protected void Button1_Click(object sender, EventArgs e)

    {

    string inventory = WebConfigurationManager.ConnectionStrings["rockwellConnectionString"].ConnectionString;

    using (OdbcConnection inventoryConnection = new OdbcConnection(inventory))

    {

    string inventorySearch = search.Text;

    inventoryConnection.Open();

    string inventoryQuery = "Select Part_number, imageUrl, drawingUrl, Description, Total_Quantity, On_Order, Quantity_In_Stock, Vendor_Name, Category_Name from vendor, logix_asset_list, logix_asset_list_category where logix_asset_list.logix_asset_list_category_id = logic_asset_list_category.logix_asset_list_category_id and logix_asset_list.Vendor_ID = vendor.Vendor_ID and Part_Number Like '%"+@inventorySearch+"%'";

    OdbcCommand inventoryCommand = new OdbcCommand(inventoryQuery,inventoryConnection);

    inventoryCommand.CommandType = CommandType.Text;

    inventoryCommand.Parameters.Add("@inventorySearch", OdbcType.Text).Value = inventorySearch;

    delegate OdbcDataReader AsyncDataReader();

    OdbcCommand cmd = null;

    IAsyncResult arInventory = new AsyncDataReader(cmd.ExecuteReader).BeginInvoke(null,null);

    }

    }

     

    The error message is: } expected 

                                           Type or namespace definition, or end-of-file expected

    Monday, June 4, 2007 6:48 AM
  • I've got the feeling that you absolutely do not understand the code... Declaring a delegate should be outside a method definition

    Code Snippet

    delegate ...

    void button_Click(...)
    {
    }


    And you should create an instance of the delegate that points to the ExecuteReader method on the instance that you're using...

    Code Snippet

    new AsyncDataReader(inventoryCommand.ExecuteReader)


    Monday, June 4, 2007 7:49 AM