如何通过comboBoxInvoice.ValueMember选择dataGridView1 [英] How Can Select By comboBoxInvoice.ValueMember to dataGridView1

查看:73
本文介绍了如何通过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;
}

解决方案

考虑Store_id是整数类型

 dr7.SelectCommand.Parameters.AddWithValue(  @ Store_id INT  .Parse(comboBoxInvoice.SelectedValue.ToString())); 


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;
                    }

解决方案

Considering Store_id is integer type

dr7.SelectCommand.Parameters.AddWithValue("@Store_id", int.Parse(comboBoxInvoice.SelectedValue.ToString()));


这篇关于如何通过comboBoxInvoice.ValueMember选择dataGridView1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆