title: How to search with parameter in MVC5 without ef
body: <p>Please, I will be happy if I someone could help me on how to create a search page in MVC 5 without using entity framework. If a user enters a product name and post, the result is displayed in a <code>GridView</code> or in an <code>InputBox</code>/<code>Label</code> for single rows. I am using C# and SQLServer at the back end. I am just a beginner in MVC and C#.</p>
  
  <p>I created a controller as shown below;</p>
  
  <pre><code>{
    connect pcon = new connect();
    using (SqlConnection conn = new SqlConnection(pcon.CS))
    {
      try
      {
        //do something
        pcon.cmd.CommandText = "SELECT * FROM tbproduct WHERE itemName=@name)";
        pcon.cmd.Parameters.Add(new SqlParameter("@name", System.Data.SqlDbType.NVarChar, 50));
        pcon.cmd.Parameters["@name"].Value = p.itemName;
        pcon.cmd.Connection = conn;
        conn.Open();
        datagridview = pcon.cmd.ExecuteReader();
        TempData["Success"] = "Record Added Sucessfully.";
        return RedirectToAction("Index", "Product");
      }
      catch (Exception ex)
      {
        // throw ex;
        // return RedirectToAction("Index", "Product");
        return View("Error", new HandleErrorInfo(ex, "Product", "AddProduct"));
      }    // end of try-catch
    }      // end of using
  }        // end of spurious open bracket
  </code></pre>
  
  <p>With this, I don't know how I would pass it to a view to get a meaningful result.
  Thank you</p>