vote up 1 vote down star

I'm trying to set the value of the sqldatasource's selectcommand parameter @ClientID as in the code below, but it's not working out.

My code:

Dim strCommand = "SELECT caller_id, phone, name, email FROM callers WHERE client_id=@ClientID"

SqlDataSource2.SelectCommand = strCommand

SqlDataSource2.SelectParameters.Add("@ClientID", iClientID)

What am I doing wrong?

flag

80% accept rate

4 Answers

vote up 1 vote down

You can set your parameter's value like that :

SqlParameter parameter1 = new SqlParameter("@ClientID", SqlDbType.BigInt);
parameter1.Value = 32;
SqlDataSource2.SelectParameters.Add(parameter1);
link|flag
Hmmm...that doesn't work, well not in VB. – thegunner Jun 12 at 20:25
vote up 0 vote down check

Never mind...configured the datasource's parameter to take the value of another control..

link|flag
vote up 0 vote down

You can workaround it by the Selecting event on the SqlDataSource, i now how frustraiting is to be restricted in this kind of controls !!!

Another alternative would be to add a HiddenField to your form, and the SqlDataSource could take its value from there.

link|flag
vote up 0 vote down

Hi,

The trick to make it work is to remove the paremeter you are trying to use before adding it. The following adapted version of your code should work:

' NOTE that there is no "@" sign when you use your parameters in the code
Parameter p = strCommandSqlDataSource2.SelectParameters["ClientID"]
strCommandSqlDataSource2.SelectParameters.Remove(p)
strCommandSqlDataSource2.SelectParameters.Add("ClientID", iClientID)

You should not use "@" sign when naming parameters in the code portion of its usage. You should use it only in the SQLCOMMAND string.

Hope it helps.

link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.