2

I am pretty new at working with this kind of thing so forgive me if my question seems too easy. I have been trying for a while at this and have searched through every relevant article I can find but I cannot get my code to work.

I want to pass a string from 'BadgeNum.Text' through a parameter on the other side and have it execute a query. I cannot get the value to pass correctly and thus cannot get any records to appear out of my query. I have tested the query multiple times using the hard-coded data and it works fine.

Any help here would be greatly appreciated.

<asp:SqlDataSource ID="GridDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:Oracle1TestString %>" 
            ProviderName="<%$ ConnectionStrings:Oracle1TestString.ProviderName %>" 
            SelectCommand="SELECT MODEL_NUMBER, SERIAL_NUMBER, DEFECT_CODE, RECORD_DATE, RECORD_TIME, PRODUCTION_DATE, AUDIT_TYPE FROM AUDITENT WHERE AUDITOR_BADGE = @BadgeNum" 
            onselecting="GridDataSource_Selecting">

            <SelectParameters>
                <asp:Parameter Name="BadgeNum" Direction="Input" DbType="String" />
            </SelectParameters>
        </asp:SqlDataSource>

Here is the code behind (C#):

protected void Page_Load(object sender, EventArgs e) {

        BadgeNum.Text = "0205096";
        Parameter badge = new Parameter();
        badge.DefaultValue = BadgeNum.Text;
        badge.Type = TypeCode.String;
        badge.Name = "BadgeNum";
        GridDataSource.SelectParameters.Add(badge);
        GridDataSource.DataBind();
}

1 Answer 1

1

OK then is your prefix possibly wrong in your select statement

@BadgeNum

vs

:BadgeNum
Sign up to request clarification or add additional context in comments.

6 Comments

That change made the page crash completely with the following server error: Exception Details: System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number
Actually, I just got the same error by removing the <SelectParameters> section from above. I think the value is actually getting through except that the Oracle DB is having a hard time handling it.
That did it! Thank you so much. You have no idea how much time I spent on this stupid little bug.
No problem, I didn't notice it was the oracle at first look
Actually, now that I got that working, I tried working in my string dates into the code. It looks like this: WHERE AUDITOR_BADGE = :BadgeNum AND RECORD_DATE => TO_DATE(:StartDate, 'MM/DD/YYYY') AND RECORD_DATE <= TO_DATE(:EndDate, 'MM/DD/YYYY') This caused an exception now too as well.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.