WPF Mysql数据对列来说太长了

时间:2014-11-30 23:21:55

标签: c# mysql wpf insert

我收到一个我不明白的错误。我有一个表单,当我按下按钮添加时,必须添加一个新行。它必须检查comboBox cb_Character和comboBox cb_Talents中的值。当我测试它我得到错误。数据太长了列,但是当我在Mysql中尝试它时,我能够做到这一点。怎么了?

 private void btn_addTalent_Click(object sender, RoutedEventArgs e)
        {
            string constring = "datasource= localhost; port=3306; username=root; password=Lorena89;";
            string Query = "SET foreign_key_checks = 0; INSERT INTO dark_heresy.learned_talents (Character_Name, Talent_Name) VALUES ('" + cb_Character + "','" + cb_Talents + "'); SET foreign_key_checks = 1; ";
            MySqlConnection conDataBase = new MySqlConnection(constring);
            MySqlCommand cmdDatabase = new MySqlCommand(Query, conDataBase);
            MySqlDataReader myReader;
            try
            {
                conDataBase.Open();
                myReader = cmdDatabase.ExecuteReader();
                MessageBox.Show("Added Talent to Character");
                while (myReader.Read())
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: \r\n" + ex);

            }     

        }

1 个答案:

答案 0 :(得分:0)

我发现了错误,我错过了.Text

('" + cb_Character.Text + "','" + cb_Talents.Text + "');