C#Visual Studio项目从组合框到texbox

时间:2017-11-18 22:10:36

标签: c# mysql visual-studio combobox

MySql,combobox和textbox有问题... 在组合框架上,我有一列表:

void ComboPlatnik()
    {
        using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
        {
            mysqlCon.Open();
            MySqlCommand mySqlCmd = new MySqlCommand("PlatnikCombo", mysqlCon);
            mySqlCmd.CommandType = CommandType.StoredProcedure;
            MySqlDataReader mysqlDr = mySqlCmd.ExecuteReader();
            while (mysqlDr.Read())
            {
                comboSolectwo.Refresh();
                comboSolectwo.Items.Add(mysqlDr.GetValue(0).ToString());
            }

        }

    }

它有效。 程序" PlatnikCombo" = SELECT nazwa FROM solectwo; 我希望在此表的第一列文本框中显示。 我创建了程序:

PROCEDURE `SolectwoViewByNazwa`(
_SolectwoNazwa Varchar(45) ) BEGIN  SELECT idsolectwa
    FROM solectwa
    WHERE nazwa = _SolectwoNazwa; END

简而言之: 如果在组合框中选择了Name_1,则在文本框中显示ID_1。

此:

private void txtIDSolectwo_TextChanged(object sender, EventArgs e)
    {
        using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
        {
            mysqlCon.Open();
            MySqlCommand mySqlCmd = new MySqlCommand("SolectwoViewByNazwa", mysqlCon);
            mySqlCmd.CommandType = CommandType.StoredProcedure;
            MySqlDataReader mysqlDr = mySqlCmd.ExecuteReader();
            while (mysqlDr.Read())
            {
                txtIDSolectwo.Text = (mysqlDr.GetValue(0).ToString());
            }
        }
    }

Dosn工作...... 请......帮助我......

1 个答案:

答案 0 :(得分:1)

我找到解决方案:

private void comboSolectwo_SelectedIndexChanged(object sender, EventArgs e)
    {
        using (MySqlConnection mysqlCon = new MySqlConnection(connectionString))
        {
            mysqlCon.Open();
            MySqlCommand mySqlCmd = new MySqlCommand("SELECT * FROM solectwa WHERE nazwa='"+comboSolectwo.Text+"';", mysqlCon);
            MySqlDataReader mysqlDr = mySqlCmd.ExecuteReader();
            while (mysqlDr.Read())
            {
                string sID = mysqlDr.GetInt32("idsolectwa").ToString();
                txtIDSolectwo.Text = sID;
            }

        }


    }

它的作品。