Please find the below code. My data is saved propelry ,now i want to display the data in the table.
[HttpPost]
public ActionResult Addmobile(Models.mobile mobile) //pass the model name as parameter
{
if (connection.State == ConnectionState.Open)
connection.Close();
connection.Open();
try
{
SqlCommand cmd = new SqlCommand("Mobile_ins",connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Mobile_brand",mobile.Mobile_brand);
cmd.Parameters.AddWithValue("@mobile_model", mobile.mobile_model);
cmd.Parameters.AddWithValue("@mobile_price", mobile.mobile_price);
cmd.Parameters.AddWithValue("@mobile_description", mobile.mobile_description);
cmd.Parameters.Add("@output", SqlDbType.Int, 0);
cmd.Parameters["@output"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
ViewBag.Msg = "Thank You";
int i = Convert.ToInt32(cmd.Parameters["output"].Value);
if (i == 1)
{
string query = "select * from [dbo].[mobile]";
SqlDataAdapter dap = new SqlDataAdapter(query, connection);
DataTable dt = new DataTable();
dap.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int x = 0; x < dt.Rows.Count; x++)
{
}
}
}
}
catch (Exception ex)
{
//throw;
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
return View("Mobile");
}
///////view code
| Mobile_Brand | Mobile_Model | Mobile_Price | Mobile_Description |
|---|


Jenith ThakkarRank #789 · 2.9K reputationPosted Jan 1, 2019, 1:46 AM EST
Debasis MohapatraRank #3,804 · 389 reputationPosted Jan 1, 2019, 10:27 PM EST
Jenith ThakkarRank #789 · 2.9K reputationPosted Jan 1, 2019, 10:30 PM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Jan 1, 2019, 7:05 PM EST
Debasis MohapatraRank #3,804 · 389 reputationPosted Jan 1, 2019, 10:30 PM EST
Sreekanth ReddyRank #726 · 3.2K reputationPosted Jan 1, 2019, 10:32 PM EST
Debasis MohapatraRank #3,804 · 389 reputationPosted Jan 1, 2019, 10:36 PM EST
Andra Chahar71 reputationPosted Jan 9, 2019, 10:58 PM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Jan 10, 2019, 5:33 PM EST