在组合框中显示检索到的值

时间:2013-07-31 15:37:32

标签: c# vb.net combobox

我从数据库访问值并在表单上显示它,我已成功显示文本框和radiobox中的重新获得的值,但我无法在combbox中显示它们。 在combox项目中,我在此combox中有值(1 2 3 4),我想显示数据库中的获取值,例如。我为combbox加入了值4,然后它应该显示4个值。 我怎么能实现这个目标?

public EditQuestionMaster(int qid_value)
{
    InitializeComponent();
    string columns = db.GetEditQuestions(qid_value);
    string[] coldata=columns.Split('~');

    txtQuestion.Text = coldata[1];
    txtOption1.Text = coldata[2];
    txtOption2.Text = coldata[3];
    txtOption3.Text = coldata[4];
    txtOption4.Text = coldata[5];
    string a = coldata[6];

    if (a == "1")
    {
        radioButton1.Checked = true;
    }
    else if (a == "2")
    {
        radioButton2.Checked = true; 
    }
    else if (a == "3")
    {
        radioButton3.Checked = true;
    }
    else if (a == "4")
    {
        radioButton4.Checked = true;
    }
        cmbMarks.ValueMember = coldata[7];//in cmbMarks.ValueMember i am getting fetched value but it is not displaying in combbox ,where i am wrong?           
}

GetEditQuestions(qid_value)代码

public string GetEditQuestions(int qid)
{
    string data = "";
    try
    {
        string sql = "select QID,Question,Opt1,Opt2,Opt3,Opt4,AnsOp,Marks from Questions where QID IN(" + qid + ") ";
        cmd = new OleDbCommand(sql, acccon);
        rs = cmd.ExecuteReader();
        if (rs.Read())
        {
            data = rs[0].ToString() + "~" + rs[1].ToString() + "~" + rs[2].ToString() + "~" + rs[3].ToString() + "~" + rs[4].ToString() + "~" + rs[5].ToString() + "~" + rs[6].ToString() + "~" + rs[7].ToString() + "$";
        }
    }
    catch (Exception err)
    {
    }
    return data;
}

提前感谢您提供任何帮助

1 个答案:

答案 0 :(得分:1)

cmbMarks.Text = coldata[7].Substring(1)

this MSDN page.Substring(1)假设coldata[7]是一个字符串,其中$为第一个字符。