Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is a strange problem that I've been working on for a while. I have a sqldatasource with select and update statements. However the statements don't work correctly with parameters.

For example if in the SQL select statement I had WHERE dept_id = '@DEPTID' and then had:

<UpdateParameters>
    <asp:Parameter Name="DEPTID" Type="string" DefaultValue="10122" />
</UpdateParameters>

It doesn't work but if I removed the UpdateParameters and put instead WHERE dept_id = '10122' it works perfectly.

And I know the parameter is being passed correctly because I put in a OnSelect="OnSqlSelecting" in the sqldatasource tag with this in the codebehind:

protected void OnSqlSelecting(Object source, SqlDataSourceCommandEventArgs e)
{
    for (int i = 0; i < e.Command.Parameters.Count; i++)
    {
        Response.Write(e.Command.Parameters[i].ParameterName.ToString() + "<br />");
        Response.Write(e.Command.Parameters[i].Value.ToString() + "<br />");
    }
}

And it gave me the correct DefaultValue for the correct parameter. I didn't provide all of my code, but what are some usual explanations or fixes for this type of problem?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Remove those single quotes from the '@DEPTID'.

Try :

WHERE [dept_id] = @DEPTID
share|improve this answer
    
Wow that's what did it. Of course it's so simple, I've only been stuck for 2 days! Thanks! –  quintonloges Apr 11 at 19:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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