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 |
|---|

Laxmidhar SahooPosted Jan 10, 2019, 10:33 PM
Andra ChaharPosted Jan 10, 2019, 3:58 AM
Debasis MohapatraPosted Jan 2, 2019, 3:36 AM
Sreekanth ReddyPosted Jan 2, 2019, 3:32 AM
Jenith ThakkarPosted Jan 2, 2019, 3:30 AM
Debasis MohapatraPosted Jan 2, 2019, 3:30 AM
Debasis MohapatraPosted Jan 2, 2019, 3:27 AM
Laxmidhar SahooPosted Jan 2, 2019, 12:05 AM
Jenith ThakkarPosted Jan 1, 2019, 6:46 AM