1

Below is my query which i want to edit in aspx file

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
     ConnectionString="<%$ ConnectionStrings:ConnectionString %>
     "InsertCommand="INSERT INTO [Sales] ([ReceiptID], [EmployeeID], [Discount], [Date])
      VALUES (@ReceiptID, @EmployeeID, @Discount, @Date)">

I want to replace the @EmployeeID with a global variable value.
How can i do that. This global variable is saved in a class which I can access by global_var_session.GID.

2
  • Are you saying that the name of your field is not actually [EmployeeID] but is actually the value stored in global_var_session.GID? Commented Dec 10, 2013 at 12:55
  • sorry see the edited question i want to replace that @employeeid with a global value. Commented Dec 10, 2013 at 13:00

2 Answers 2

1

You can use InsertParameters:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
 ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
 InsertCommand="INSERT INTO [Sales] ([ReceiptID], [EmployeeID], [Discount], [Date])
 VALUES (@ReceiptID, @Gid, @Discount, @Date)">

    <InsertParameters>
        <asp:Parameter Name="Gid" Type="String" />
        ...define other parameters...
    </InsertParameters>
</asp:SqlDataSource>

And in code-behind use

SqlDataSource2.InsertParameters["Gid"].DefaultValue = global_var_session.GID;
...set other parameter values...
Sign up to request clarification or add additional context in comments.

Comments

0

I would remove the InsertCommand from the aspx and move it to the cs. Then in the .cs under the appropriate event handler:

SqlDatasource2.InsertCommand= "your query string with the reference to your Global Variable"

Comments

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.