Microsoft Office Tutorials and References
In Depth Information
{
entityList.Add(new Entity1
{
BusinessEntityID = Int32.Parse(reader[0].ToString()),
NationalIDNumber = reader.GetString(1),
LoginID = reader.GetString(2),
JobTitle = reader.GetString(3),
BirthDate = DateTime.Parse(reader[4].ToString()),
MaritalStatus = char.Parse(reader[5].ToString()),
Gender = char.Parse(reader[6].ToString()),
HireDate = DateTime.Parse(reader[7].ToString()),
SalariedFlag = bool.Parse(reader[8].ToString()),
VacationHours = Int16.Parse(reader[9].ToString()),
SickLeaveHours = Int16.Parse(reader[10].ToString()),
CurrentFlag = bool.Parse(reader[11].ToString()),
ModifiedDate = DateTime.Parse(reader[12].ToString())
});
}
reader.Close();
}
}
return entityList;
13.
Copy the code in Listing 4-6 for the ReadItem method into the entity1service.cs file.
Listing 4-6. The ReadItem Method
Entity1 entity = new Entity1();
using (SqlConnection conn = new SqlConnection(
"Data Source=<DB Server Name>; Integrated Security=SSPI; Initial
Catalog=AdventureWorks2012"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("uspGetEmployeesById", conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@BusinessEntityID", System.Data.SqlDbType.Int).Value = id;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
entity.BusinessEntityID = Int32.Parse(reader[0].ToString());
entity.NationalIDNumber = reader.GetString(1);
entity.LoginID = reader.GetString(2);
entity.JobTitle = reader.GetString(3);
entity.BirthDate = DateTime.Parse(reader[4].ToString());
entity.MaritalStatus = char.Parse(reader[5].ToString());
entity.Gender = char.Parse(reader[6].ToString());
entity.HireDate = DateTime.Parse(reader[7].ToString());
entity.SalariedFlag = bool.Parse(reader[8].ToString());
entity.VacationHours = Int16.Parse(reader[9].ToString());
entity.SickLeaveHours = Int16.Parse(reader[10].ToString());
entity.CurrentFlag = bool.Parse(reader[11].ToString());
 
Search JabSto ::




Custom Search