Open();
string sql = ?«select EmpCode, EmpName, Basic,
JoiningDate, DeptCode from employee e, Department
d where e.DeptID = d.DeptID and
d.DeptCode = ????» + deptCode + ?«'?»;
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader dr = cmd.ExecuteReader();
employeeList = new ArrayList();
while (dr.Read())
{
Employee emp = new Employee();
if (dr[?«EmpCode?»] != DBNull.Value)
emp.EmpCode = dr[?«EmpCode?»].ToString();
if (dr[?«EmpName?»] != DBNull.Value)
emp.EmpName = dr[?«EmpName?»].ToString();
if (dr[?«Basic?»] != DBNull.Value)
emp.Basic = Convert.ToDouble(dr[?«Basic?»].
ToString());
if (dr[?«JoiningDate?»] != DBNull.Value)
emp.JoiningDate =
Convert.ToDateTime(dr[?«JoiningDate?»].
ToString());
if (dr[?«DeptCode?»] != DBNull.Value)
Chapter 1
[ 13 ]
emp.DeptCode = dr["DeptCode"].ToString();
employeeList.Add(emp);
emp = null;
}
}
catch
{
throw;
}
finally
{
conn.Close();
}
return employeeList;
}
}
In this code, the GetAllEmployees() method returns all records from the Employee
table, whereas, the GetEmployeeByDept() method returns the records of all
employees of a specific department.
New Data Source Controls in ASP.NET 2.0
With ASP.NET 2.0, data binding has been simplified a lot with the introduction of
a number of data source controls.
Pages:
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33