Debasis Mohapatra

Debasis Mohapatra

  • NA
  • 381
  • 56.7k

Want to display the data in the table

Jan 1 2019 6:07 AM
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
<table cellpadding="9" cellspacing="56">
<thead>
<tr>
<th>Mobile_Brand</th>
<th>Mobile_Model</th>
<th>Mobile_Price</th>
<th>Mobile_Description</th>
</tr>
</thead>
</table>

Answers (9)