【问题标题】:c# Window Form How Select mysql Data In Textbox1?c#窗口窗体如何在Textbox1中选择mysql数据?
【发布时间】:2015-01-31 00:33:03
【问题描述】:

我是编程部分的新手,所以请不要尝试糟糕的帮助。 实际上,我从 phpmyadmin 到 c# windows form textbox1.Text 区域的焦点数据失败了。

我的数据库名:business,表名:life,列名:Email_id

我需要在我的 textbox1.Text 区域中显示电子邮件 ID 10 号行。

查看我的代码

       string connString = "datasource=x5x.1x1.13x.xxx;Database=business;username=sumon;password=root";
       MySqlConnection connect = new MySqlConnection(connString);
       MySqlCommand myCommand = connect.CreateCommand();

       string input = textBox1.Text;

       myCommand.CommandText = "SELECT * FROM life WHERE id = @input";
       connect.Open();

       MySqlDataReader reader = myCommand.ExecuteReader();

       if (reader.Read())
           textBox1.Text = reader["*"].ToString();

       connect.Close();

【问题讨论】:

  • 你有什么问题?

标签: c# mysql phpmyadmin


【解决方案1】:

您错过了为@input 设置值。我编辑了你的代码(没有测试)。试一试。

   string connString = "datasource=x5x.1x1.13x.xxx;Database=business;username=sumon;password=root";
   MySqlConnection connect = new MySqlConnection(connString);
   MySqlCommand myCommand = connect.CreateCommand();

   myCommand.Parameters.Add(new SqlParameter("input", 10));

   //string input = textBox1.Text;

   myCommand.CommandText = "SELECT * FROM life WHERE id = @input";
   connect.Open();
       MySqlDataReader reader = myCommand.ExecuteReader();

       if (reader.Read())
           textBox1.Text = reader["Email_id"].ToString();

       connect.Close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 1970-01-01
    相关资源
    最近更新 更多