public IEnumerable<Bus> GetBussesForCenter(string center) { SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Busses WHERE comCenter =@center",sqlConnection); List<Bus> busses = new List<Bus>(); // name SqlParameter sqlParameter = new SqlParameter("@center", SqlDbType.NVarChar); sqlParameter.Value = center; sqlCommand.Parameters.Add(sqlParameter); SqlDataReader reader = null; try { reader = sqlCommand.ExecuteReader(); while(reader.Read()) { Bus b = new Bus(); b.RegNo = Convert.ToString(reader[0]); b.ComCenter = Convert.ToString(reader[1]); busses.Add(b); } } catch(Exception e) { Debug.WriteLine(e.Message); } finally { if(reader != null) reader.Close(); } return busses; }
public IEnumerable<Bus> GetAllBusses() { SqlCommand sqlCommand = new SqlCommand("select * from Busses",sqlConnection); SqlDataReader reader = null; List<Bus> busses = new List<Bus>(); try { reader = sqlCommand.ExecuteReader(); while(reader.Read()) { Bus b = new Bus(); b.RegNo = Convert.ToString(reader[0]); b.ComCenter = Convert.ToString(reader[1]); busses.Add(b); } } catch(Exception e) { Debug.WriteLine(e.Message); } finally { if(reader != null) reader.Close(); } return busses; }
private Bus GetBus(String regNo) { SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Busses WHERE regNo='" + regNo + "'", sqlConnection); SqlDataReader reader = null; Bus b = null; try { reader = sqlCommand.ExecuteReader(); while(reader.Read()) { b = new Bus(); b.RegNo = Convert.ToString(reader[0]); b.ComCenter = Convert.ToString(reader[1]); } } catch(Exception e) { Debug.WriteLine(e.Message); } finally { if(reader != null) { reader.Close(); } } return b; }
private Bus GetBus(string bus) { SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Busses WHERE regNo='"+bus+"';"); Bus b = null; try { SqlDataReader reader = sqlCommand.ExecuteReader(); while(reader.Read()) { b = new Bus(); b.RegNo = Convert.ToString(reader[0]); b.ComCenter = Convert.ToString(reader[1]); } } catch(Exception e) { Debug.WriteLine(e.Message); } return b; }