public static List <model.supplier> find_all()//查询出所有客户 { MySqlConnection conn = Util.Util.getConn(); String sql = "select * from supplier"; MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); DataSet ds = new DataSet(); Console.WriteLine("ds:" + ds); da.Fill(ds); conn.Close(); //获得DataSet里的数据 List <model.supplier> rs = new List <model.supplier>(); if (ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0)//判断DataSet里是否有值 { rs = new List <model.supplier>(); int count = ds.Tables[0].Rows.Count;//获得表的行数 for (int i = 0; i < count; i++) { model.supplier r = new model.supplier(); r.Id = (int)ds.Tables[0].Rows[i]["id"]; r.Supplier_number = (string)ds.Tables[0].Rows[i]["supplier_number"]; r.Supplier_name = (string)ds.Tables[0].Rows[i]["supplier_name"]; r.Charge_name = (string)ds.Tables[0].Rows[i]["charge_name"]; r.Telephone = (string)ds.Tables[0].Rows[i]["telephone"]; r.Address = (string)ds.Tables[0].Rows[i]["adress"]; r.Type = (string)ds.Tables[0].Rows[i]["type"]; rs.Add(r); } } return(rs); }
private void supplier_update_Load(object sender, EventArgs e) { Console.Write("!!!!!" + number); model.supplier r = dao.supplierDaoz.select(number); Number.Text = r.Supplier_number; Name1.Text = r.Supplier_name; }
public static List <model.supplier> selectAll(String number) { MySqlConnection conn = Util.Util.getConn(); MySqlDataReader dataReader = null; MySqlCommand command = null; List <model.supplier> kehus = new List <model.supplier>(); model.supplier r = new model.supplier(); try { command = conn.CreateCommand(); command.CommandText = "SELECT * FROM supplier where supplier_number='" + number + "'"; dataReader = command.ExecuteReader(); Console.WriteLine(); while (dataReader.Read()) { r.Id = dataReader.GetInt16(0); r.Supplier_number = dataReader.GetString(1); r.Supplier_name = dataReader.GetString(2); r.Charge_name = dataReader.GetString(3); r.Telephone = dataReader.GetString(4); r.Address = dataReader.GetString(5); r.Type = dataReader.GetString(6); kehus.Add(r); } } catch (Exception) { MessageBox.Show("查询出错!"); } finally { if (!dataReader.IsClosed) { dataReader.Close(); } if (conn.State == ConnectionState.Open) { conn.Close(); } } return(kehus); }