Search code examples
asp.netsqldatasource

asp.net sql query - bind the default value of a parameter to the return value of a method from code behind


 <asp:Parameter Name="Creator_Id" Type="Int32"  DefaultValue="<%=currentEmployeeId() %>"/>

or

INSERT INTO [PromotionSet] ([StartDate], [EndDate], [Bonus], [Text], [InfoImage], [RequiresPreregistration], [Code], [Creator_Id]) VALUES (@StartDate, @EndDate, @Bonus, @Text, @InfoImage, @RequiresPreregistration, @Code,<%=currentEmployeeId() %>"

Neither of the above means of achieving the same thing work. currentEmployeeId returns the id of the current logged in user. If currentEmployeeId is set to return simply "1"(return "1"). it still doesn't work. But if I replace <%=currentEmployeeId() %> by 1 it works.

Doesn't inline code work in this scenarios? How should I accomplish this?

Object data source is out of the question-I don't have time to write the insert update and delete methods myself(This is why I use SQLDataSource)

Many thanks


Solution

  • You can do it from codebehind

    protected void Page_Load(object sender, EventArgs e)
    {
         mySqlDataSourece.SelectParameters["Creator_Id"].DefaultValue = currentEmployeeId();
    
    }