Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
C#
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;
                    }
Posted
Updated 12-May-15 5:18am
v2
Comments
CHill60 12-May-15 11:19am    
What is wrong with your code?
Samira Radwan 12-May-15 16:54pm    
If I understand correctly, you want to use comboBox selected value as parameter for your second query, so you should change this: comboBoxInvoice.ValueMember to comboBoxInvoice.SelectedValue.

1 solution

Considering Store_id is integer type
C#
dr7.SelectCommand.Parameters.AddWithValue("@Store_id", int.Parse(comboBoxInvoice.SelectedValue.ToString()));
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900