// GET: ERP /// <summary> /// Calls the "sp_GetStores" stored procedure, and displays the results in the view. /// </summary> /// <returns></returns> public ActionResult Index() { string connectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = SimonStore; Integrated Security = True; Connect Timeout = 15; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"; System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString); connection.Open(); System.Data.SqlClient.SqlCommand command = connection.CreateCommand(); command.CommandText = "sp_GetStores"; command.CommandType = System.Data.CommandType.StoredProcedure; System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader(); List <Models.ERPStoreModel> stores = new List <Models.ERPStoreModel>(); while (reader.Read()) { Models.ERPStoreModel store = new Models.ERPStoreModel(); //the reader is "untyped" - I need to look at the //stored procedure definition to see that the 1st column returned is an int store.ID = reader.GetInt32(0); store.Name = reader.GetString(1); //Adds the newly created store to the list stores.Add(store); } connection.Close(); return(View(stores)); }
public ActionResult Add(Models.ERPStoreModel model) { //TODO: Insert the data from the model into the database using the "ExecuteNonQuery" method on SQLCommand return(RedirectToAction("Index")); }