I am using the UltraWebGrid and want to track who is making a change to the data. I am using stored procedures for my select, insert, update and delete commands in the grid. When someone updates a record, I would like to send the username (current user logged in) to the stored procedure so that it can be updated in the table, but I can't figure out how to send the username as a parameter. Any help is appreciated. Thanks!
Hmmm...even when I change it so that the SQLSataSource uses SQL statements instead of stored procedures, I still can't seem to figure out how to send the UserName.
My code looks like this right now: INSERT INTO tblLookup_Diag_Codes_CHF(Diag_Code) SELECT Diag_Code = @Diag_Code
but I want it to look like this: INSERT INTO tblLookup_Diag_Codes_CHF(Diag_Code, Inserted_By) SELECT Diag_Code = @Diag_Code, Inserted_By = @Inserted_By
except I need the @Inserted_By to be the login of the user that is currently logged in.
I found another page through MSDN that may help:Using Parameterized Queries with the SqlDataSource
In particular, take a look at "Step 5: Assigning Parameter Values Programmatically".
This is exactly what I was hoping I would be able to use. I actually tried this before posting, but could never get it to work correctly. This is what my code looks like: As you can see, I tried to add the username defaultvalue, and it works...kind of...it actually inserts "<% HttpContext.Current.User.Identity.Name %>" into the table. I'm just not sure of the proper syntax I should be using at this point.
<asp:SqlDataSource ID="SqlDataSource" runat="server"ConnectionString="<%$ ConnectionStrings:MTMPConnectionString %>"DeleteCommand="usp_del_tblLookup_Diag_Codes_CHF"InsertCommand="usp_ins_tblLookup_Diag_Codes_CHF"SelectCommand="usp_get_tblLookup_Diag_Codes_CHF"UpdateCommand="usp_upd_tblLookup_Diag_Codes_CHF"OnInserted="SqlDataSource_Inserted"DeleteCommandType="StoredProcedure"InsertCommandType="StoredProcedure"SelectCommandType="StoredProcedure"UpdateCommandType="StoredProcedure"><DeleteParameters><asp:Parameter Name="Lookup_ID" Type="Int32" /></DeleteParameters><UpdateParameters><asp:Parameter Name="Lookup_ID" Type="Int32" /><asp:Parameter Name="Diag_Code" Type="String" /></UpdateParameters><InsertParameters><asp:Parameter Name="Diag_Code" Type="String" /><asp:Parameter Name="User_Name" Type="String" DefaultValue="<% HttpContext.Current.User.Identity.Name %>" /></InsertParameters></asp:SqlDataSource>