private List <Testdir> gridf8view() { var conn = Database.ConnectDB(); conn.Open(); string query = "select * from tb_testdir;"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader reader = cmd.ExecuteReader(); List <Testdir> list = new List <Testdir>(); while (reader.Read()) { Testdir tdir1 = new Testdir(); tdir1.ID = reader.GetInt32(reader.GetOrdinal("Testdir_id")); tdir1.testname = reader.GetString(reader.GetOrdinal("test_name")); tdir1.price = reader.GetInt32(reader.GetOrdinal("Price")); tdir1.testcode = reader.GetString(reader.GetOrdinal("test_code")); list.Add(tdir1); } conn.Close(); return(list); }
public void loadcombotest() { var conn = Database.ConnectDB(); conn.Open(); string query = "select test_name, price from tb_testdir;"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader reader = cmd.ExecuteReader(); List <Testdir> list = new List <Testdir>(); while (reader.Read()) { Testdir tdir = new Testdir(); tdir.testname = reader.GetString(reader.GetOrdinal("test_name")); tdir.price = reader.GetInt32(reader.GetOrdinal("price")); int count = 1; tdir.ID = count; count++; list.Add(tdir); } combof7_test.DataSource = list; combof7_test.ValueMember = "ID"; combof7_test.DisplayMember = "testname"; conn.Close(); }