在文本框中的不同行上显示数据库中的值C#

时间:2014-10-04 15:31:56

标签: c# mysql textbox rows

我一直在研究这个程序,它将帐户从数据库中拉出来,并将它们显示在一个文本框中我到目前为止工作,但它只会从第一行的数据库中取出帐户。这是我的代码:

 string myConnection = "datasource=xxxx;port=3306;username=xxxx;password=xxxx!";
        string Query = "select * from xxx.xxx;";
        MySqlConnection conDataBase = new MySqlConnection(myConnection);
        MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
        MySqlDataReader myReader;
        DataTable dt = new DataTable();
        try 
        {
            conDataBase.Open();
             myReader = cmdDataBase.ExecuteReader();
             while (myReader.Read())
             {
                 string sUsername = myReader.GetString("usernames");
                 string sPasswords = myReader.GetString("passwords");
                 nsTextBox1.Text = sUsername + ":" + sPasswords;



             }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

还有,所以它会删除旧的用户名+密码并显示新的用户名+

1 个答案:

答案 0 :(得分:0)

喜欢这个?:

nsTextBox1.Text += sUsername + ":" + sPasswords + Enviroment.NewLine;

此外,您的TextBox需要是多行的。

一定是TextBox吗?为什么不使用ListBox?

相关问题