【问题标题】:Inserting Two values using MYSQL into a combobox.item.add使用 MYSQL 将两个值插入 combobox.item.add
【发布时间】:2019-03-17 16:03:20
【问题描述】:

因此,我试图在我学校的投票系统项目中的组合框中添加名字和姓氏。我收到一个错误,即 getString 无法在这种类型的语法中使用。有没有其他方法可以将此值添加到我的组合框的 1 个单个插槽中?

 using (MySqlConnection con = new MySqlConnection(connection))
            {
                //Opening of Connection
                con.Open();
                MySqlDataReader dataReader;

                //FOR PRESIDENT
                using (MySqlCommand votePresident = new MySqlCommand(displayPresident, con))
                {

                    try
                    {
                        int votePres = 0;
                        votePres = votePresident.ExecuteNonQuery();
                        dataReader = votePresident.ExecuteReader();
                    //Loop to read the Data
                    while (dataReader.Read())
                    {
                        String rollPres = dataReader.GetString("firstName","lastName");
                        presidentbox.Items.Add(rollPres);
                    }

                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show("Failed to Vote" + ex);
                    }

                }

Error Shows this

【问题讨论】:

    标签: c# mysql database


    【解决方案1】:

    搜索互联网时问题已解决 我用它来连接两个字符串

    while (dataReader.Read())
                        {
                            String rollPresf = dataReader.GetString("firstName");
                            String rollPresl = dataReader.GetString("lastName");
                            presidentbox.Items.Add(rollPresf + " " + rollPresl);
                        }
    

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2012-04-22
      • 2018-04-19
      • 2020-07-15
      • 1970-01-01
      • 2015-10-04
      相关资源
      最近更新 更多