Hey
I would like to know if someone can direct me to code samples on how to update data of current logged in user, coming from labels and textboxes thats typed in by the current logged in user!
I would apprecaite this so much, I have been hitting my head trying to figure this out for about 12 long hours...
Thank you so much
![]() |
0 |
![]() |
Do you program with C# or VB?
I assume that you have a table (outside of the Membership database table) that holds the fields that you want to have updated data. Is this the case?
Also, I'm thinking you will just be getting update values from textboxes.
The value of a label could be extracted and put into a SQL command to update a field in a table, but since you don't modify the value of a label I don't see how this will be helpful.
as hs mentions in the next post, we need to know if you want to update the ASPNETDB info or if you want to update a table that you created. I was guessing the second option because I think you would want to have more fields of information than what are provided in the ASPNETDB tables.
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
i guess you are talking about the authentication ticket you issue after login when you say labels and text boxes.
You did not say whether you hv used asp.net 2.0 provided membership api or not.
One way to do what you say is
HttpContext.Current.User.Identity.Name.ToString()
If you used membership api then
its easy to update Profile.<propertyname>
Do not hit your head hard , coz that why this forum is for.Gain and then share knowledge.
Please tell us what login mechanism you're using.tha will help us more...abt the prob..
News & Reviews | Matrimonial | Mithila
![]() |
0 |
![]() |
Hey thank you for both of your response
First of all I'm using asp.net vb code
What Im trying to achieve, is finding the current logged in user's UserId (which in the asp.net Membership table) ,.. that UserId is also a foreign key in CompanyDetails datatable.
So knowing the UserId
I would like to pull all the data of the current user out of CompanyDetails datatable and display it in Textboxes
then I would like to be able to update current users updated info back into the CompanyDetails datatable
I would like to use Sqldatasource control for achieving
Thank you for taking the time to help me
Regards
![]() |
0 |
![]() |
You can display the identity of who is logged in with a control on the front page or you get get it using the code behind page (and you will need this one). The example below shows both. I'll come back next with an example that does the other part of what you asked to see.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WhoAreYou.aspx.vb" Inherits="WhoAreYou" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <p>CSI theme music here...</p> <p>You are logged in as: <asp:LoginName ID="LoginName1" runat="server" /> </p> <p>Push the button to retrieve this information using the code behind:</p> <p> <asp:Button ID="Button1" runat="server" Text="Get it dynamically" /></p> <p> <asp:Label ID="CodeBehindIdentityCheckLabel" runat="server"></asp:Label></p> </div> </form> </body> </html>
Imports System.Web.Security Partial Class WhoAreYou Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim whoareyoustring As String = Membership.GetUser().ToString() CodeBehindIdentityCheckLabel.Text = "from the code behind page I can see you are " + whoareyoustring Catch ex As Exception CodeBehindIdentityCheckLabel.Text = "There is a problem... Maybe you are not logged in?" CodeBehindIdentityCheckLabel.Text = "<br /><br />" CodeBehindIdentityCheckLabel.Text = "<a href='VB_Login.aspx'>Login</a>" End Try End Sub End Class
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
I'm going to write an example that has a SqlDataSource.
Now, in order to do that, that means we will be using controls on the aspx page. When I post the code it will be quite a bit, but you should know that this code is manually typed--it is generated automatically using wizards. Have you done this before?
We will use a DetailsView which lets you focus in on one record, the record for the user for whom you want to update the data.
There will be two SqlDataSource controls. The first one will find the users in the table. It will "feed" these to a DropDownList control.
The second SqlDataSource will "see" the user chosen on the DropDownList and give this to the DetailsView.
I'm wondering if after showing the code for the pages, that it might be good to talk about the use of the wizards (SqlDataSource wizard, DropDownList wizard, DetailsView wizard).
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MakeAndPopulateTable.aspx.vb" Inherits="MakeAndPopulateTable" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="CreatePopulateButton" runat="server" Text="Create & Populate" /> <br /><br /> <asp:Label ID="Label1" runat="server" Text="Push the button once..."></asp:Label> </div> </form> </body> </html>
Imports System.Data.SqlClient Imports System.Data Partial Class MakeAndPopulateTable Inherits System.Web.UI.Page Protected Sub CreatePopulateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreatePopulateButton.Click Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True") Dim SQLstatements As String = "CREATE TABLE CompanyDetails " SQLstatements += "(id smallint IDENTITY(1,1) PRIMARY KEY, " SQLstatements += "login nvarchar(20) NOT NULL, " SQLstatements += "companyname nvarchar(50) NOT NULL, " SQLstatements += "employeecount int NOT NULL, " SQLstatements += "accountbalance real NOT NULL) " SQLstatements += "INSERT INTO CompanyDetails (login, companyname, employeecount, accountbalance) VALUES ('jlocke', 'Locke Enterprises, Inc.', 150, 2000) " SQLstatements += "INSERT INTO CompanyDetails (login, companyname, employeecount, accountbalance) VALUES ('asmith', 'Acme London Division, Ltd.', 180, 2000) " SQLstatements += "INSERT INTO CompanyDetails (login, companyname, employeecount, accountbalance) VALUES ('wsmith', 'Acme Cologne Division, Bv.', 160, 2000) " Dim cmd As SqlCommand = New SqlCommand(SQLstatements, conn) cmd.CommandType = CommandType.Text conn.Open() cmd.ExecuteNonQuery() conn.Close() Label1.Text = "Table created and populated..." End Sub End Class
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="UpdateCompanyDetails.aspx.vb" Inherits="UpdateCompanyDetails" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [login] FROM [CompanyDetails]"></asp:SqlDataSource> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="login" DataValueField="login"> </asp:DropDownList> <br /><br /> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [CompanyDetails] WHERE [id] = @original_id AND [login] = @original_login AND [companyname] = @original_companyname AND [employeecount] = @original_employeecount AND [accountbalance] = @original_accountbalance" InsertCommand="INSERT INTO [CompanyDetails] ([login], [companyname], [employeecount], [accountbalance]) VALUES (@login, @companyname, @employeecount, @accountbalance)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [CompanyDetails] WHERE ([login] = @login)" UpdateCommand="UPDATE [CompanyDetails] SET [login] = @login, [companyname] = @companyname, [employeecount] = @employeecount, [accountbalance] = @accountbalance WHERE [id] = @original_id AND [login] = @original_login AND [companyname] = @original_companyname AND [employeecount] = @original_employeecount AND [accountbalance] = @original_accountbalance"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="login" PropertyName="SelectedValue" Type="String" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="original_id" Type="Int16" /> <asp:Parameter Name="original_login" Type="String" /> <asp:Parameter Name="original_companyname" Type="String" /> <asp:Parameter Name="original_employeecount" Type="Int32" /> <asp:Parameter Name="original_accountbalance" Type="Single" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="login" Type="String" /> <asp:Parameter Name="companyname" Type="String" /> <asp:Parameter Name="employeecount" Type="Int32" /> <asp:Parameter Name="accountbalance" Type="Single" /> <asp:Parameter Name="original_id" Type="Int16" /> <asp:Parameter Name="original_login" Type="String" /> <asp:Parameter Name="original_companyname" Type="String" /> <asp:Parameter Name="original_employeecount" Type="Int32" /> <asp:Parameter Name="original_accountbalance" Type="Single" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="login" Type="String" /> <asp:Parameter Name="companyname" Type="String" /> <asp:Parameter Name="employeecount" Type="Int32" /> <asp:Parameter Name="accountbalance" Type="Single" /> </InsertParameters> </asp:SqlDataSource> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="id" DataSourceID="SqlDataSource2" Height="50px" Width="300px"> <Fields> <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" /> <asp:BoundField DataField="login" HeaderText="login" SortExpression="login" /> <asp:BoundField DataField="companyname" HeaderText="companyname" SortExpression="companyname" /> <asp:BoundField DataField="employeecount" HeaderText="employeecount" SortExpression="employeecount" /> <asp:BoundField DataField="accountbalance" HeaderText="accountbalance" SortExpression="accountbalance" /> <asp:CommandField ShowEditButton="True" /> </Fields> </asp:DetailsView> </form> </div> </body> </html>
Partial Class UpdateCompanyDetails Inherits System.Web.UI.Page End Class
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
The work to make the aspx page was all drag and drop (or double click) and then use the wizards.
1. Drag and drop SqlDataSource from ToolBox.
2. Drag and drop DropDownList from ToolBox.
3. Change view from ‘Source’ to ‘Design’.
4. Go to the northeast corner of the SqlDataSource and when the square with the > appears, click on it.
5. Click “Configure Data Source”.
6. Click on the bar under the question “Which data connection should …”
7. I’m assuming that you will want to choose ConnectionString for your ConnectionString. This assumes you accepted this default name when you set things up previously.
8. Click Next.
9. Under Name Choose CompanyDetails.
10. Click the CheckBox for login.
11. Click Finish (you are done).
12. Go to the northeast corner of the DropDownList and when the square with the > appears, click on it.
13. Click ‘ChoseDataSource’.
14. Under Select a data source choose ‘SqlDataSource1’.
15. Because we only chose ‘login’, there is only one thing we could put into either category (login) so this happens automatically.
16. Click OK.
17. Click ‘Enable AutoPostBack’.
Click Save and test the page. The DropDownList should show the login names of the clients.
For the next part, there are three different things to do, selecting the asterisk, going into the WHERE button and making choices and going into the ADVANCE and making choices. Because of the way I did it below I ended up out of the wizard before we were finished so we had to go back in to do the last step. After I post this I’ll go back and see how to do it better.
18. Place the cursor below the DropDownList.
19. Go to ToolBox and double click SqlDataSource (it will be given the default name SqlDataSource2).
20. Position the cursor below SqlDataSource2.
21. Go to the ToolBox and double click DetailsView.
22. Click the > symbol in the northeast corner of SqlDataSource2.
23. Click ‘Configure Data Source’.
24. Choose ‘Connection String’ under the question “Which data connection should…”
25. Click Next.
26. Under Name, choose CompanyDetails.
26a. Under Columns, check the checkbox for the asterisk (*).
27. Go over to the right and click “WHERE”.
28. Under Column choose login.
29. Under Source, choose control.
30. Under ControlID (at the top on the right side) choose DropDownList1.
31. Click the Add button, further on the right, a little more than half way down.
32. Click OK.
(loss of numbering because a revision was made)
35. Click ADVANCED.
36. Click the CheckBox for Generate INSERT, UPDATE, and DELETE statements.
37. Click the CheckBox that now appears for Use Optimistic Concurrency.
38. Click Next and Finish.
39. Click the > symbol in the northeast corner of the DetailsView.
40. For Choose Data Source choose SqlDataSource2.
41. Click the CheckBox for Enable Editing. You are done.
I went to the DetailsView on the front page and changed the width from 125px (the computer chose this) to 300px.
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
Hey :-)
Thank you so much for your time and work so far...the second last letter you wrote with code to show me how to get the
Membership.GetUser().ToString()..I got so far to achieve that,and your code works well to help me understand howthank you so much......your question to me is 'the code is manually typed--it is generated automatically using wizards.have I done this before?"I'm not entirely sure what you mean,but following your next code samples will help me to understand .I have done quite a bit of Sqldatasource and parameters but I have no clue how to bind the Membership.GetUser().ToString()
with the sqldatasource, and there's no information on google on this...but you next sample codes will hugely help meI thank you for all your help so far, it means a lot to me.Regardsps....hahaha just after i wrote this, I saw you posted the next sample codes ...I shall go through them..and let you knowthank you so much again :-)
![]() |
0 |
![]() |
I'm holding my breath a little on the wizards. I'm thinking that might be better learned from a video. I can't say though that there is a video out that that shows configuring a SqlDataSource doing three things: chosing fields (we chose all with asterisk), going into WHERE, going into ADVANCED.
I'm hoping the going into Advanced part is fairly easy--just click both checkboxes. It can be vexacious to a beginner if they don't check that first box (to enable things) and later when they go to the control they don't have the choices that they want.
The second SqlDataSource required some more advanced moves to get it working since it takes its information from another control. Any questions on it?
Larry Dechent - Sampson Coatings
www.wemakebetterpaint.com has 29 examples (C# & VB) to help beginners with ASP.NET.
![]() |
0 |
![]() |
Hey
Thank you for those codes,you seriously gone out of your way to help to me,thank you so much
It was fairly easy to understand everything,and the sqldatasource 2 was very intuative for me thank you so much, I actually change your code a bit (but was exactly the same principal as what you explained to me )
what I done was instead of linking the detailsview up with a dropdownlist (well that scenario will be good for a administrative section on a website..choosing a username and updating data)
I change the where clause control on sqldatasource2 to the CodeBehindIdentityCheckLabel.Text (and change the codebind for
Dim whoareyoustring As String = Membership.GetUser().ToString()
CodeBehindIdentityCheckLabel.Text = whoareyoustringso when the user login and the detailsview will appear with his/her detail
my code is for anyone in the future
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Default" %>
<div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<p>CSI theme music here...</p>
<p>You are logged in as:
<asp:LoginName ID="LoginName1" runat="server" />
</p>
<p>Push the button to retrieve this information using the code behind:</p>
<p>
</p>
<p>
<asp:Label ID="CodeBehindIdentityCheckLabel" runat="server"></asp:Label> </p>
<p>
</p>
<p>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" Height="50px" Style="position: relative" Width="301px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="login" HeaderText="login" SortExpression="login" />
<asp:BoundField DataField="companyname" HeaderText="companyname" SortExpression="companyname" />
<asp:BoundField DataField="employeecount" HeaderText="employeecount" SortExpression="employeecount" />
<asp:BoundField DataField="accountbalance" HeaderText="accountbalance" SortExpression="accountbalance" />
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>" DeleteCommand="DELETE FROM [CompanyDetails2] WHERE [id] = @original_id AND [login] = @original_login AND [companyname] = @original_companyname AND [employeecount] = @original_employeecount AND [accountbalance] = @original_accountbalance"
InsertCommand="INSERT INTO [CompanyDetails2] ([login], [companyname], [employeecount], [accountbalance]) VALUES (@login, @companyname, @employeecount, @accountbalance)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [CompanyDetails2] WHERE ([login] = @login)"
UpdateCommand="UPDATE [CompanyDetails2] SET [login] = @login, [companyname] = @companyname, [employeecount] = @employeecount, [accountbalance] = @accountbalance WHERE [id] = @original_id AND [login] = @original_login AND [companyname] = @original_companyname AND [employeecount] = @original_employeecount AND [accountbalance] = @original_accountbalance">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_login" Type="String" />
<asp:Parameter Name="original_companyname" Type="String" />
<asp:Parameter Name="original_employeecount" Type="Int32" />
<asp:Parameter Name="original_accountbalance" Type="Single" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="login" Type="String" />
<asp:Parameter Name="companyname" Type="String" />
<asp:Parameter Name="employeecount" Type="Int32" />
<asp:Parameter Name="accountbalance" Type="Single" />
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_login" Type="String" />
<asp:Parameter Name="original_companyname" Type="String" />
<asp:Parameter Name="original_employeecount" Type="Int32" />
<asp:Parameter Name="original_accountbalance" Type="Single" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="CodeBehindIdentityCheckLabel" Name="login" PropertyName="Text"
Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="login" Type="String" />
<asp:Parameter Name="companyname" Type="String" />
<asp:Parameter Name="employeecount" Type="Int32" />
<asp:Parameter Name="accountbalance" Type="Single" />
</InsertParameters>
</asp:SqlDataSource>
</p>
<p>
</p>
</div></div>
</form>
</body>
</html>
codebehind
Imports System.Web.Security
Partial Class Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim whoareyoustring As String = Membership.GetUser().ToString()
CodeBehindIdentityCheckLabel.Text = whoareyoustring
Catch ex As Exception
CodeBehindIdentityCheckLabel.Text = "There is a problem... Maybe you are not logged in?"
CodeBehindIdentityCheckLabel.Text = "<br /><br />"
CodeBehindIdentityCheckLabel.Text = "<a href='Login.aspx'>Login</a>"
End Try
End Sub
End Class
So you must be logged in to use this code...
this is a scenario for when user login they see all there data in the detailsview
Thank you so much again idechent,it's people like you that makes the world great...
Thank you
Regards
![]() |
0 |
![]() |