Friday, March 23, 2012

insert value captured from session into database table

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT Quiz.Title, UserQuiz.DateTimeComplete, UserQuiz.Score FROM UserQuiz INNER JOIN Quiz ON UserQuiz.QuizID = Quiz.QuizID WHERE (UserQuiz.UserName = @.UserName) ORDER BY UserQuiz.DateTimeComplete">
<SelectParameters>
<asp:SessionParameter Name="UserName" SessionField="UserName" />
</SelectParameters>
</asp:SqlDataSource
how to modify this code so that it can insert value of the username captured in the session to the database table record?

you have to add one Insert Command with a parameter. that read from Session["UserName"]

Hope this help.

|||how it should be code men ?

<InsertParameters>
<asp:Parameter ?????? />
</Insert Parameter|||thanks men... i guest i got it now

should be :

<InsertParameters>
<asp:SessionParameter Name="UserName" SessionField="UserName">
</InsertParameters>|||

I think the best way to do it is that do it once through wizard then look at the code generated by wizard. it helped me before.

Hope this help.

sql

No comments:

Post a Comment