Tayyab Jatoi

Tayyab Jatoi

  • NA
  • 135
  • 26.5k

I want to search the rows which matches given keyword.

Oct 8 2019 10:42 AM
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.
  1. private void btnSaleSearch_Click(object sender, EventArgs e)  
  2. {  
  3. SqlConnection conn = new SqlConnection(myconnstrng);  
  4. //Create Datatable to hold the data frmo database  
  5. DataTable dt = new DataTable();  
  6. try  
  7. {  
  8. decimal j = 0;  
  9. string sql = "select Name, SUM(Balance_Amt) As Balance_Amt from tbl_Transactions_Rak Group By Name";  
  10. SqlCommand cmd = new SqlCommand(sql, conn);  
  11. //Sql data Adapter to hold the values from database temporarily  
  12. SqlDataAdapter adapter = new SqlDataAdapter(cmd);  
  13. //open Database connection  
  14. conn.Open();  
  15. adapter.Fill(dt);  
  16. dataGridView.DataSource = dt;  
  17. foreach (DataRow dr in dt.Rows)  
  18. {  
  19. j = j + Convert.ToDecimal(dr["Balance_Amt"].ToString());  
  20. }  
  21. }  
  22. catch (Exception ex)  
  23. {  
  24. MessageBox.Show(ex.Message);  
  25. }  
  26. finally  
  27. {  
  28. conn.Close();  
  29. }  
  30. {  
  31. }  
  32. }  

Attachment: Capture.rar

Answers (2)