private void cbActiveCustomers_SelectedIndexChanged(object sender, EventArgs e) { ComboObject currentObject = (ComboObject)cbActiveCustomers.SelectedItem; int CustomerID = currentObject.CustomerID; DataTable dtOrders = new DataTable(); try { // dataGridView1.DataSource = GivMe.OrdersByName(CustomerID); SqlCommand sqlComm = new SqlCommand("sp_CustomerSales", sqlConn); sqlComm.CommandType = CommandType.StoredProcedure; SqlParameter prmCustomerID = new SqlParameter("@CustID", CustomerID); sqlComm.Parameters.Add(prmCustomerID); SqlDataAdapter sqlDa = new SqlDataAdapter(sqlComm); sqlDa.Fill(dtOrders); textBox1.Text = CustomerID.ToString(); dataGridView1.DataSource = dtOrders; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cbCustomers_SelectedIndexChanged(object sender, EventArgs e) { //Here is the code for when the user clicks an object in the form's combo box. try { //First we check to see if a connection can be established to the database. if (SqlConnect.dataConnect() == true) { //Then a Combo Object object is created, which holds the values of what was clicked on by the user. Then the value of the CustomerID //in that object is put into another variable. ComboObject current = (ComboObject)cbCustomers.SelectedItem; int CustomerID = current.CustomID; //Then real quick, a datatable is created that will populate the datagrid on the form later on. DataTable dtCustomerOrders = new DataTable(); //Next, as there will be a parameter playing into what results are returned, a SqlCommand is created using the //other stored procedure that was created for this assignment. It's then categorized as a stored procedure, so it can have //parameters set to it. SqlCommand sqlCom = new SqlCommand("dbo.sp_CustomerSalesInfo", SqlConnect.sqlConn); sqlCom.CommandType = CommandType.StoredProcedure; //Here a parameter is created, where it states what parameter in the stored procedure it's supplying a value for, and what variable //in this program currently contains the value that will be supplied to the parameter. The parameter is then added to the parameters //of the SQL command. SqlParameter prmCustID = new SqlParameter("@CustID", CustomerID); sqlCom.Parameters.Add(prmCustID); //A data adapter then gets the information from the database based on the conditions set. SqlDataAdapter dataFeed = new SqlDataAdapter(sqlCom); //The adapter then fills the data table created earlier. dataFeed.Fill(dtCustomerOrders); //Finally, the data table populates the data grid on the form. dgResults.DataSource = dtCustomerOrders; } else { //This is for the occasion that the program is unable to connect to the SQL database. An exception is thrown telling the user //that the program failed to connect to the database. throw new Exception("Unable to connect to the AdventureWorks2012 database."); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void storeSalaryGradeMany_OnRefreshData(object sender, StoreRefreshDataEventArgs e) { if (string.IsNullOrEmpty(hdfQuantumIdMany.Text)) { return; } var quantum = CatalogQuantumController.GetById(Convert.ToInt32(hdfQuantumIdMany.Text)); if (quantum == null) { return; } var quantumGrade = CatalogGroupQuantumController.GetById(quantum.GroupQuantumId); if (quantumGrade == null) { return; } var grade = quantumGrade.GradeMax; hdfSalaryGradeMany.Text = grade.ToString(); var comboObjects = new List <ComboObject>(); for (var i = 1; i <= grade; i++) { var combo = new ComboObject { Code = i.ToString(), Name = "Bậc " + i }; comboObjects.Add(combo); } storeSalaryGradeMany.DataSource = comboObjects; storeSalaryGradeMany.DataBind(); }