public ArrayList getProducts() { using (SqlConnection con = new SqlConnection(ConnectionString)) { SqlCommand cmd = new SqlCommand("procReturnAllProducts", con); cmd.CommandType = CommandType.StoredProcedure; ArrayList productsList = new ArrayList(); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Products products = new Products(Convert.ToInt32(reader["productID"]), Convert.ToString(reader["productName"]), Convert.ToInt32(reader["supplierID"]), Convert.ToInt32(reader["categoryID"]), Convert.ToString(reader["quantityPerUnit"]), Convert.ToDouble(reader["unitPrice"]), Convert.ToInt16(reader["unitInStoct"]), Convert.ToInt16(reader["unitOnOrder"]), Convert.ToInt16(reader["reOrderLevel"]), Convert.ToBoolean(reader["discontinue"])); productsList.Add(products); }//End while reader.Close(); } catch (SqlException) { throw new ApplicationException("Error connection to database"); } return productsList; }//End Using }
public partial class Form1 : Form { public ProductsBL productBL; public ArrayList prodList; public Form1() { InitializeComponent(); productBL = new ProductsBL(); prodList = new ArrayList(); prodList = productBL.getProducts(); dataGridView1.DataSource = prodList; } }
int a = reader.GetInt32(reader.GetOrdinal("productID"));
reader["productID"]
productID
procReturnAllProducts
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)