private void CustomerCB_SelectedIndexChanged(object sender, EventArgs e) { cboObject current = (cboObject)CustomerCB.SelectedItem; int CustomerID = current.CustomerID; DataTable dtCustomerOrders = new DataTable(); try {// passing the stored procedure 'sales' to sql SqlCommand sqlCom = new SqlCommand("dbo.sp_SalesBS1", sqlConnection); sqlCom.CommandType = CommandType.StoredProcedure; //establishing the parameter to the customer id SqlParameter prmCustID = new SqlParameter("@CustomerID", CustomerID); sqlCom.Parameters.Add(prmCustID); SqlDataAdapter dataFeed = new SqlDataAdapter(sqlCom); dataFeed.Fill(dtCustomerOrders); dataGrid.DataSource = dtCustomerOrders; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void comboBoxCustomerName_SelectedIndexChanged(object sender, EventArgs e) { cboObject currentObject = (cboObject)comboBoxCustomerName.SelectedItem; int SelectedCustomerID = currentObject.CustomerID; try { dataGridActiveCustomers.DataSource = dataWorks.dtSalesorderDetailsByCustomer(SelectedCustomerID); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error ..."); } }
private void cbCustName_SelectedIndexChanged(object sender, EventArgs e) { // Once a new customer name is selected from the combo box, pull up that particular // person's order history. // Finds my cboObject class, then it uses the data provided from the form // and populates the data in the class cboObject currentObject = (cboObject)cbCustName.SelectedItem; // Variable declaration // Sets CustomerID variable to the CustomerID variable in the cboObject class int CustomerID = currentObject.CustomerID; // Creates a new data table DataTable dtCustomerOrders = new DataTable(); try { // SQL Command to run the stored procedure from SQL database SqlCommand sqlComm = new SqlCommand("spSalesOrderSearch", sqlConn); // Sets the command type to a stored procedure sqlComm.CommandType = CommandType.StoredProcedure; // Adds a parameter to the stored procedure (This is so the stored procedure knows // what data to pull and provide to the form SqlParameter prmCustomerID = new SqlParameter("@CustomerID", CustomerID); sqlComm.Parameters.Add(prmCustomerID); // Establishes a new data adapter SqlDataAdapter sqlDa = new SqlDataAdapter(sqlComm); // Data adapter fills the data table sqlDa.Fill(dtCustomerOrders); // Establishes that the data grid will be filled with data from the data table dgOrders.DataSource = dtCustomerOrders; // Sets text in the tbCustomerID Text box to equal the customer ID the is currently selected tbCustomerID.Text = CustomerID.ToString(); // Clears text box upod new selection of a customer tbSalesID.Text = ""; } catch (Exception ex) { // Error handeling MessageBox.Show(ex.Message, "Something with terribly wrong..."); } }