Firstly, im a PHP developer trying to get my head around asp.net.
so i have created a basic MVC project.
I have a query without the fields known (ie. select * from products) how do I:
-
execute in Controller - my attempt:
public ActionResult getProducts() { using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["myDB"].ToString())) { string sql = "select * from products"; SqlCommand cmd = new SqlCommand(sql, cn); cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); } return View(); }
-
how do i pass the results to a View and then loop through them like:
foreach ($data as $key => $val) { echo $key.' = '.$val.'<br>'; }
please help as this is SOOOOO simple in PHP but seems to be very confusing in asp.net.
ps. sorry for the formatting.
cheers, trav.