none
OdbcCommandBuilder.DeriveParameters() / SqlCommandBuilder.DeriveParameters() RRS feed

  • Question

  • Hi all,

    I have this:

                    cn = new OdbcConnection("Driver={SQL Server};Server=My-PC01;Database=Northwind;Trusted_Connection=Yes");
    
                    OdbcCommand cmd = new OdbcCommand("{? = call dbo.usp_TestParameters (?, ?)}", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cn.Open();
                    OdbcCommandBuilder.DeriveParameters(cmd);
    

    But the count from cmd.Parameters is alway 0.

    However, If I use SqlClient, the count from cmd.Parameters is alway 3.

    Can someone tell me why 

    OdbcCommandBuilder.DeriveParameters() does not work?

    Thanks in advance.

    Monday, March 3, 2014 4:35 AM

Answers

  • Hello,

    I am confused that why you call the store procedure like:

    “{? = call dbo.usp_TestParameters (?, ?)}”, if I call it in SqlClinet, it will throw an error, however it runs ok in OdbcClient just without returning parameter count.

    Usually, we can the store procedure like below:

    OdbcCommand cmd = new OdbcCommand("dbo.ProGetOrderName", connection);//("{? = call dbo.usp_TestParameters (?, ?)}",

    Here I make an example which can return correct parameter count:

    string connectionString = @"Driver={SQL Server Native Client 11.0};Server=(localdb)\Projects;Database=DFDB;Trusted_Connection=yes;";
    
                OdbcConnection connection = new OdbcConnection(connectionString);
    
                try
    
                {
    
                    connection.Open();
    
                    OdbcCommand cmd = new OdbcCommand("dbo.ProGetOrderName", connection);//("{? = call dbo.usp_TestParameters (?, ?)}", 
    
                    cmd.CommandType = CommandType.StoredProcedure;
    
                    OdbcParameterCollection pl = cmd.Parameters;
    
                    OdbcCommandBuilder.DeriveParameters(cmd);
    
                    pl = cmd.Parameters;
    
                    Console.WriteLine("Connect Success!");
    
                }
    
                catch (Exception ex)
    
                {
    
                    Console.WriteLine(ex.Message);
    
                }
    
                finally
    
                {
    
                    connection.Close();
    
                }
    
                Console.ReadLine();
    

    You can have a try.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 4, 2014 3:18 AM
    Moderator