Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay so the title says what I'm trying to do.

This is what I have so far
C#
private void Form2_Load(object sender, EventArgs e)
        {
            label5.Text = "To update a new user simply click on there name to the left \n edit the form and click Update User";

            myConnection.GetConnection();
            DataSet sds = new DataSet();
            MySqlCommand sql = new MySqlCommand("SELECT * FROM users", myConnection.GetConnection());
            MySqlDataAdapter mydap = new MySqlDataAdapter(sql);
            mydap.Fill(sds, "users");
            this.UserList.DataSource = sds.Tables["users"];
            this.UserList.DisplayMember = "name";

        }

        private void UserList_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int cid = Int32.Parse(this.UserList.SelectedValue.ToString());
            MySqlCommand sql1 = new MySqlCommand("SELECT * FROM users WHERE name = '" + this.UserList.SelectedValue.ToString() + "'", myConnection.GetConnection());
            MySqlDataAdapter DA = new MySqlDataAdapter(sql1);
            DataSet DS = new DataSet();
            DA.Fill(DS, "users");

            this.Usernametxtbox.Text = DS.Tables[0].Rows[0]["name"].ToString();
        }


I really don't understand how to do this at all, so if someone could help me out with maybe an example or somthing it wouild be great.
(Or even point me in the right direction)

I've been trying to get this to work for the last 2 days :(
Posted
Updated 21-Oct-10 4:55am
v2
Comments
Dalek Dave 21-Oct-10 10:55am    
Edited for Grammar.
Sandeep Mewara 21-Oct-10 11:26am    
Sorry if I have missed but whats the issue?
Tunacha 21-Oct-10 12:10pm    
i keep getting No rows at point 0 on
this.Usernametxtbox.Text = DS.Tables[0].Rows[0]["name"].ToString();
and i dont know why

1 solution

clarification regarding your question "Populate textbox on listbox selection" in your code you are getting the user name from this statement "this.UserList.SelectedValue.ToString() ", then if you want to show the name of the user in text box then use the same statement "this.UserList.SelectedValue.ToString()". else i am not getting what you want to set in the text box.
 
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