anh hoang

anh hoang

  • NA
  • 3
  • 1.3k

TabControl with procedures (SqlServer)!

Dec 7 2011 8:40 PM
Hi everybody!
I am Winform (C#) beginer. I have a problem. My project use 3 layers include DA, GUI, BL. GUI has frm_Main. I use TabControl in this one. In Tabcontrol i has dataGridView1. In BL i wrote 

public void HienThi(string Employ_ID ,string Employ_Name, string Employ_Birth)
       { 
 connection.Open();
  SqlCommand cmd = new SqlCommand();
  cmd.Connection = connection.GetConnection;
  cmd.CommandText = "[dbo].[InFO]"
  cmd.CommandType = System.Data.CommandType.StoredProcedure;
  SqlParameter []pl = new SqlParameter[3];
  if (Employ_ID != null || Employ_Name!=null || Employ_Birth!= null)
  {
  pl[0] = new SqlParameter("@MaNV", MaNV);
  pl[1] = new SqlParameter("@TenNV", TenNV);
  pl[2] = new SqlParameter("@NgaySinh", NgaySinh);
  }
  else
  { 
  pl[0] = new SqlParameter("@MaNV", DBNull.Value);
  pl[1] = new SqlParameter("@TenNV", DBNull.Value);
  pl[2] = new SqlParameter("@NgaySinh", DBNull.Value);
  }
  cmd.Parameters.AddRange(pl);   
  SqlDataAdapter adp = new SqlDataAdapter(cmd);
  DataTable tb = new DataTable();
 ((DataGridView)frm.Controls["dataGridView1"]).DataSource = tb; // error in here
 connection.Close();
      }

CAN YOU: fix this code ((DataGridView)frm.Controls["dataGridView1"]).DataSource = tb; 
Thanks!                      










Answers (3)