I have a table where for one person i have several records.
I have combined several record for one person in one row with the following code and having total balance in this row.
Question
Now my challenge is i want to search the person by using keyword.Like if i give name it will display only that person row in the datagrid view??
*Form is attached with with post.
- private void btnSaleSearch_Click(object sender, EventArgs e)
- {
- SqlConnection conn = new SqlConnection(myconnstrng);
-
- DataTable dt = new DataTable();
- try
- {
- decimal j = 0;
- string sql = "select Name, SUM(Balance_Amt) As Balance_Amt from tbl_Transactions_Rak Group By Name";
- SqlCommand cmd = new SqlCommand(sql, conn);
-
- SqlDataAdapter adapter = new SqlDataAdapter(cmd);
-
- conn.Open();
- adapter.Fill(dt);
- dataGridView.DataSource = dt;
- foreach (DataRow dr in dt.Rows)
- {
- j = j + Convert.ToDecimal(dr["Balance_Amt"].ToString());
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- conn.Close();
- }
- {
- }
- }