本文介绍了如何通过comboBoxInvoice.ValueMember选择dataGridView1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string query = 从StoresTBL中选择Store_id,Store_name;
SqlDataAdapter da = new SqlDataAdapter(query,con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds, StoresTBL);
comboBoxInvoice.DisplayMember = Store_name;
comboBoxInvoice.ValueMember = Store_id;
comboBoxInvoice.DataSource = ds.Tables [ StoresTBL];
DataTable dt5 = new DataTable();
string CS = ConfigurationManager.ConnectionStrings [ DBCS跨度>]的ConnectionString。
使用(SqlConnection con = new SqlConnection(CS))
{
string sqlstr5 = 选择rnh.ReceiptNote_id为'收货单ID',rnh.Customer_id为'客户ID',位于pt.Product_id = rnd.Product_Id,其中rnh.Receipt_Date = CONVERT(VARCHAR(10),GETDATE(),110)和st.Store_id = @Store_id;
使用(SqlDataAdapter dr7 = new SqlDataAdapter(sqlstr5,CS))
{
dr7.SelectCommand.Parameters.AddWithValue( @ Store_id,comboBoxInvoice .ValueMember);
dr7.Fill(dt5);
dataGridView1.DataSource = dt5;
}
解决方案
string query = "select Store_id,Store_name from StoresTBL"; SqlDataAdapter da = new SqlDataAdapter(query, con); con.Open(); DataSet ds = new DataSet(); da.Fill(ds, "StoresTBL"); comboBoxInvoice.DisplayMember = "Store_name"; comboBoxInvoice.ValueMember = "Store_id"; comboBoxInvoice.DataSource = ds.Tables["StoresTBL"]; DataTable dt5 = new DataTable(); string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(CS)) { string sqlstr5 = "select rnh.ReceiptNote_id as 'Receipt Note Id', rnh.Customer_id as'Customer Id' on pt.Product_id=rnd.Product_Id where rnh.Receipt_Date=CONVERT(VARCHAR(10),GETDATE(),110) and st.Store_id= @Store_id"; using (SqlDataAdapter dr7 = new SqlDataAdapter(sqlstr5, CS)) { dr7.SelectCommand.Parameters.AddWithValue("@Store_id", comboBoxInvoice.ValueMember); dr7.Fill(dt5); dataGridView1.DataSource = dt5; }
解决方案
这篇关于如何通过comboBoxInvoice.ValueMember选择dataGridView1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!