public static List <String[]> getCTHDbyID(String id) { SqlConnection conn = Connection.GetConnection(); conn.Open(); List <String[]> result = new List <String[]>(); String sql = $"select CTHoaDon.id,CTHoaDon.soluong,ThietBi.id,ThietBi.ten,ThietBi.gia,ThietBi.soluong,ThietBi.loai from CTHoaDon, ThietBi where CTHoaDon.idthietbi = ThietBi.id AND CTHoaDon.id='{id}'"; try { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { String[] tmp = new String[10]; for (int i = 0; i < reader.FieldCount; i++) { tmp[i] = reader[i].ToString(); } result.Add(tmp); } } ; return(result); } catch (Exception e) { Console.WriteLine("Error: " + e); Console.WriteLine(e.StackTrace); return(result); } finally { conn.Close(); conn.Dispose(); } }
public static String[] getLoaiTB() { String[] result = {}; SqlConnection conn = Connection.GetConnection(); conn.Open(); String sql = "SELECT loai FROM ThietBi GROUP BY loai"; try { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; SqlDataReader reader = cmd.ExecuteReader(); List <String> tmp = new List <string>(); while (reader.Read()) { tmp.Add(reader[0].ToString()); } result = new string[tmp.Count]; for (int i = 0; i < tmp.Count; i++) { result[i] = tmp[i]; } return(result); } catch (Exception e) { Console.WriteLine("Error: " + e); Console.WriteLine(e.StackTrace); return(result); } finally { conn.Close(); conn.Dispose(); } }