开发者

How to change UserName in ASPNETDB.MDF

I am doing some howmework, and my userName is located in an automatically created Database, called ASPNET.DB

I need to change the value of the field user name, but i dontKnow how to call the primary key if the table(userName).

This is what i did:

protected void brukEndringerButton_Click(object sender, EventArgs e)
    {
        string txtInput = navnTextBox.Text;        

        SqlDataAdapter adapter;
        DataSet dataset = new DataSet();
        SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\ASPNETDB.MDF;Trusted_Connection=True;User Instance=yes");

        String comm = "SELECT * FROM Informasjon";
        adapter = new SqlDataAdapter(comm, conn);
        SqlCommandBuilder commandBuild = new SqlCommandBuilder(adapter);
        adapter.Fill(dataset, "Informasjon");

        DataRow dr = dataset.Tables["Informasjon"].Rows[???????]开发者_开发技巧;

        dr["UserName"] = txtInput;

        adapter.Update(dataset, "Informasjon");
        conn.Close();

        infoLabel.Text = "Endringer som gjøres!";
    }

Some how i need to find the Row with a given userId so the program will know what Row needs to Update. I don't know how to get that data, the only thing i can call is

User.Identity.name;

Any ideas how can i modify that column?


It sounds like you may be using the asp.net membership provider. If so, all the info you need is right in the docs: http://msdn.microsoft.com/en-us/library/system.web.security.membership.aspx

No need to work directly with the database (assuming you are using the membership provider).


If you want to do it this way, try having a hidden field with the previous value of the username. Now you can add a Where statement to your sql.

Or

You can use MembershipService to get the MembershipUser where the username = User.Identity.name

The ProviderUserKey is the userid.

That should be enough to get you on your way, I don't want to give you to much if it is for homework.

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜