public List <Material_certificate> GetMT() { List <Material_certificate> MCL = new List <Material_certificate>(); SqlConnection con = null; try { con = Connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "SELECT * FROM GLN_Material_certificate"; SqlCommand cmd = new SqlCommand(selectSTR, con); // get a reader SqlDataReader dr = cmd.ExecuteReader();//(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end while (dr.Read()) { // Read till the end of the data into a row Material_certificate a = new Material_certificate(); a.NumMaterial = Convert.ToInt32(dr["NumMaterial"]); a.ShippingCertificate = (string)(dr["ShippingCertificate"]); a.Amountcertificate = Convert.ToInt32(dr["Amountcertificate"]); MCL.Add(a); } dr.Close(); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } return(MCL); }
// GET api/<controller> public List <Material_certificate> Get() { Material_certificate MT = new Material_certificate(); return(MT.GetMT()); }