本文介绍了在列表框选择中填充文本框(mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,标题说明了我要做什么.
这是我到目前为止所拥有的
私有 void Form2_Load(对象发件人,EventArgs e)
{
label5.Text = " 要更新新用户,只需单击左侧的名称\ n编辑表单,然后单击Update用户" ;
myConnection.GetConnection();
DataSet sds = 新 DataSet();
MySqlCommand sql = 新 MySqlCommand(" SELECT * FROM users" ,myConnection.GetConnection());
MySqlDataAdapter mydap = 新 MySqlDataAdapter(sql);
mydap.Fill(sds," 用户" );
此 .UserList.DataSource = sds.Tables [" 用户"];
此 .UserList.DisplayMember = " 名称" ;
}
私有 无效 UserList_SelectedIndexChanged(对象发件人,EventArgs e)
{
// int cid = Int32.Parse(this.UserList.SelectedValue.ToString());
MySqlCommand sql1 = 新建 MySqlCommand(" 选择*来自用户的位置名称='" + 此 .UserList.SelectedValue.ToString()+ " '",myConnection.GetConnection());
MySqlDataAdapter DA = 新 MySqlDataAdapter(sql1);
DataSet DS = 新 DataSet();
DA.Fill(DS," 用户" );
此.Usernametxtbox.Text= DS.Tables [ 0 ].Rows [ 0 ] [" 名称"].ToString();
}
我真的根本不明白该怎么做,所以如果有人可以帮我一个例子或某事,那将是很棒的.
(或者甚至指向正确的方向)
我一直在努力使它在最近的两天内工作:(<解决方案
Okay so the title says what I''m trying to do.
This is what I have so far
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 :(
解决方案
这篇关于在列表框选择中填充文本框(mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!