本文介绍了我正在从组合框中的数据库中获取数据.但是,从组合框中选择任何项目后,我在相关文本框中未获得相关记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
    SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   ='" + comboBox3.SelectedValue.ToString() + "'", objConn1);
    DataSet ds = new DataSet();
    da.Fill(ds, "dbo.GateEntry");
    if (ds.Tables["dbo.GateEntry"].Rows.Count > 0)
    {
        textBox3.Text = ds.Tables["GateEntry"].Rows[0]["Customer"].ToString();
        textBox1.Text = ds.Tables["GateEntry"].Rows[0]["Delivery"].ToString();
        comboBox1.SelectedItem = ds.Tables["GateEntry"].Rows[0]["Mode"].ToString();
        comboBox2.SelectedItem = ds.Tables["GateEntry"].Rows[0]["Inout"].ToString();
        textBox2.Text = ds.Tables["GateEntry"].Rows[0]["boxes"].ToString();
        dateTimePicker1.Value = Convert.ToDateTime(ds.Tables["GateEntry"].Rows[0]["Time"].ToString());
        textBox4.Text = ds.Tables["GateEntry"].Rows[0]["Person"].ToString();
        textBox5.Text = ds.Tables["GateEntry"].Rows[0]["Approved"].ToString();

    }
    else 
    {
    
    }
}

推荐答案

SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   ='" + comboBox3.SelectedValue.ToString().Trim() + "'", objConn1);


SqlDataAdapter da = new SqlDataAdapter("select * from GateEntry where Delivery   LIKE'" + comboBox3.SelectedValue.ToString() + "%'", objConn1);



希望这些对您有帮助.



hope any of these help you..


这篇关于我正在从组合框中的数据库中获取数据.但是,从组合框中选择任何项目后,我在相关文本框中未获得相关记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 11:59