如何编辑当前用户数据 [英] How to edit current users data

查看:80
本文介绍了如何编辑当前用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建用户帐户,用户可以在其中编辑他的数据,例如:姓名,电子邮件,密码,登录等。我使用了登录表单身份验证。我想从数据库(SQL)显示用户数据并编辑它们并保存更改。有人可以帮我解决这个问题吗?编写此代码的最佳方法是什么?






由PIEBALDconsult重新定位。



我试过但我做错了。我试图用storedproceduer重新编写这篇文章http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx方法RunStoredProcParams。我遇到了以下错误:对象引用未设置为对象的实例,必须声明标量变量userid。我试图通过声明(Guid)(Membership.GetUser()。ProviderUserKey)等来解决它。但我最大的问题是选择当前用户数据。 Ials尝试使用我的代码,其中用户角色管理员可以编辑一些数据,如更改角色或阻止用户。显示数据的方法如下:



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:

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.

推荐答案

会员11187739写道:
Member 11187739 wrote:

我试图在这里显示一条记录,但我不能。

I was trying here to display ony one record but I couldn't.





鉴于您已经拥有DataTable中的所有数据...



在代码中你显示,您需要从DataGridView的DataSource属性中的DataSet访问DataTable。



您可以使用DefaultView属性或在同一个表上创建新的DataView :

http://msdn.microsoft。 com / en-us / library / 22x98asf(v = vs.110).aspx [ ^ ]



并设置其RowFilter属性:



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



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



然后dv.Rows应仅包含带有该ID的一行。



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.


成员11187739写道:
Member 11187739 wrote:

对象引用未设置为实例一个对象,必须声明标量变量userid

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.


您好,感谢您的建议。我解决了它对你的建议。非常感谢。
Hi, thank you for your suggestions. I solved it rearging to yours suggestion. Thank you very much.


这篇关于如何编辑当前用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆