An SqlParameter with parametername "ID" is not contained by this SqlParameterCollection

Posted on 2006-05-04
Last Modified: 2008-01-09

i create a sqldataadapter in windows form and create a criteria for a column. I want to add parameter to dataadapter's selectcommand with column name but it gives an error.

"An SqlParameter with parametername "ID" is not contained by this SqlParameterCollection"

My select command which is created by dataadapter:
this.sqlSelectCommand1.CommandText = "SELECT ID, ad, soyad FROM tablo WHERE (ID = @Param2)";

And my code to add parameter to this command:

i don't want to access to this parameter with @param2 value, i want to access with ID value.

Thanks for help guys..
Question by:sercanparlak
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]

    this.sqlSelectCommand1.CommandText = "SELECT ID, ad, soyad FROM tablo WHERE (ID = @ID)";

    SqlParameter param  = new SqlParameter();
        param.ParameterName = "@ID";
        param.Value         = textbox1.text;


    Author Comment

    thanks for answer angel but i don't want to use @ID for parameter. i want to use ? for parameter as in my code.

    querybuilder in dataadapter i defined my sqlcommand like this :
    SELECT ID, ad, soyad FROM tablo WHERE (ID = ?)

    now i want to access this parameter with ID name like this :

    i am waiting your answers..
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    the problem is that there is no name "ID" assigned automatically to the parameter by the querybuilder.

    you might try to use the index instead of a name:

    or, as shown above, build the command text and the parameters collection manually (recommended)

    Author Comment

    i can access to the parameter by two ways:

    this.sqlSelectCommand1.CommandText = "SELECT ID, ad, soyad FROM tablo WHERE (ID = @Param2)";


    but i want to access as in here :

    like this : sqlDataAdapter1.SelectCommand.Parameters["ID"].Value=textBox1.Text;
    LVL 142

    Accepted Solution


    this.sqlSelectCommand1.CommandText = "SELECT ID, ad, soyad FROM tablo WHERE (ID = ?)";

    Author Comment

    i read an article that say in oledb you can use parameters name when passing but if you're using sqlclient you cann't use parameter's name. Thanks for replies angel...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    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!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now