Click here to Skip to main content
15,883,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I want to create users account where user can edit his data, eg: name, email, password, login etc. I userd Forms Authentication for Login. I want to display users data from database (SQL) and edit them and save changes. Can someone help me with this problem? What is the best way to write this code?



Relocated by PIEBALDconsult.

I've tried but I'm doing something wrong. I was trying to do this with storedproceduer rearging to this article http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx method RunStoredProcParams. I was having errors like: Object reference not set to an instance of an object, Must Declare the scalar variable userid. I've tried to solve it by declaring (Guid)(Membership.GetUser().ProviderUserKey) etc. But my biggest problem is to select current users data. Ials have tried to use my code where user role admin can edit some data like change role or block user. Method for displaying data looks like this:

C#
private void PobierzDane()
        {
            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CS"].ConnectionString))
            {
                string wyswietl = "SELECT [id_uzytkownika], [imie], [nazwisko], [PESEL], [email], [login]"
                    + ", [haslo], [rola], [blokada] FROM Uzytkownik";
                using (SqlCommand cmd = new SqlCommand())
                {
                    con.Open();
                    cmd.Connection = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = wyswietl;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridViewKierUzytkownik.DataSource = ds;
                    GridViewKierUzytkownik.DataBind();
                    con.Close();
                }
            }

I was trying here to display ony one record but I couldn't.
Posted
Updated 11-Nov-14 5:01am
v2
Comments
PIEBALDconsult 11-Nov-14 9:15am    
We can't help until you've tried it.
Member 11187739 11-Nov-14 9:49am    
-- Relocated to Question --
PIEBALDconsult 11-Nov-14 9:55am    
Don't put that in a comment; use Improve question and put it in the question.
Richard Deeming 11-Nov-14 9:49am    
The asp.net site has lots of tutorials to get you started:
http://www.asp.net/web-forms/overview[^]

Member 11187739 wrote:
I was trying here to display ony one record but I couldn't.


Given that you already have all the data in a DataTable...

In the code you show, you'll need to access the DataTable from the DataSet in the DataGridView's DataSource property.

You can use the DefaultView property or create a new DataView on the same table:
http://msdn.microsoft.com/en-us/library/22x98asf(v=vs.110).aspx[^]

and set its RowFilter property:

dv.RowFilter = System.String.Format ( "id_uzytkownika={0}" , ID )

http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter(v=vs.110).aspx[^]

Then dv.Rows should contain only the one row with that ID.
 
Share this answer
 
v3
Member 11187739 wrote:
Object reference not set to an instance of an object, Must Declare the scalar variable userid


That is often caused by not setting a parameter value, but you would need to show that code as well. Possibly in a new Question.
 
Share this answer
 
v2
Hi, thank you for your suggestions. I solved it rearging to yours suggestion. Thank you very much.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900