如何更改C#中每个组合框项的值

如何更改C#中每个组合框项的值

本文介绍了如何更改C#中每个组合框项的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助才能在MS Access数据库中获取数字输出。那个comboBOx项目是字符。



我尝试过:



  private   void  comboBox1_SelectedIndexChanged_1(对象发​​件人,EventArgs e)
{
如果(comboBox1.Text == Mr){comboBox1.SelectedValue = 1; }
if (comboBox1.Text == 太太){comboBox1.SelectedValue = 2; }
}

private void button1_Click( object sender,EventArgs e)
{


try
{
OleDbConnection con = new OleDbConnection( @ Provider = Microsoft.ACE.OLEDB.12.0; Data Source = D:\ dropdown.accdb; Persist Security Info = True);
OleDbCommand cmd = con.CreateCommand();
con.Open();
cmd.CommandText = INSERT INTO下拉列表([AS_TITLE],[Name])VALUES(' + comboBox1.SelectedValue + ',' + textBox1.Text + ');

cmd.Connection = con;
cmd.ExecuteNonQuery();



MessageBox.Show( 已成功上传);
con.Close();

}


catch (例外ee)
{
MessageBox .Show(ee.Message);
}
解决方案

Need help to get numeric output in MS Access database. That comboBOx items are characters.

What I have tried:

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (comboBox1.Text == "Mr") { comboBox1.SelectedValue = "1"; }
            if (comboBox1.Text == "Mrs") { comboBox1.SelectedValue = "2"; }
        } 

private void button1_Click(object sender, EventArgs e)
        {
            
           
            try
            {
                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\dropdown.accdb; Persist Security Info = True");
                OleDbCommand cmd = con.CreateCommand();
                con.Open();
                cmd.CommandText = "INSERT INTO dropdown([AS_TITLE],[Name]) VALUES ('" + comboBox1.SelectedValue + "','" + textBox1.Text + "')";
                
                cmd.Connection = con;
                cmd.ExecuteNonQuery();

                
                
            MessageBox.Show("Successfully Uploaded");
                con.Close();
                
            }


            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
解决方案


这篇关于如何更改C#中每个组合框项的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 01:33