第1个回答 2013-07-09
public static List<Pet> GetPet()
{
GetConn();
string sql = "select * from pets";
comm = new SqlCommand(sql, conn);
reader=comm.ExecuteReader();
List<Pet> list=new List<Pet>();
while(reader.Read())
{
Pet pet = new Pet();
pet.Id =Convert.ToInt32(reader["id"]);
pet.Name = Convert.ToString(reader["name"]);
pet.CreatDate = Convert.ToDateTime(reader["creatDate"]);
pet.Reamerk = reader["Reamerk"].ToString();
list.Add(pet);
}
return list;
}
public static int DeletePet(int id)
{
GetConn();
string sql = "delete from pets where id=" + id;
comm = new SqlCommand(sql, conn);
return comm.ExecuteNonQuery();
}
public static int InsertPet(Pet pet)
{
GetConn();
string sql = "insert into Pets values ('"+pet.Name+"','"+pet.CreatDate+"','"+pet.Reamerk+"')";
comm = new SqlCommand(sql,conn);
return comm.ExecuteNonQuery();
}
public static int UpdatePet(Pet pet)
{
GetConn();
string sql = "update pets set Name='" + pet.Name + "',CreatDate='" + pet.CreatDate + "',Reamerk='" + pet.Reamerk + "' where id="+pet.Id+"";
comm = new SqlCommand(sql, conn);
return comm.ExecuteNonQuery();
}本回答被网友采纳