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?