hi iam doing a project on asp.net .I am able to display data in my project but what i want to get is if i click on button named as "ADDQUEUEDETAILS" i should insert data into database,can anyone help me out .Iam uploading my code if there is any modifications in my code let me know.
This is my controller code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
using Getqueuedetails.Models;
using Getqueuedetails.Controllers;
cmd.Parameters.AddWithValue("@ReleaseId", ReleaseId != null ? Convert.ToInt32(ReleaseId) : 0);
cmd.Parameters.AddWithValue("@ReleaseName", ReleaseName);
cmd.Parameters.AddWithValue("@Scopelockdate", Scopelockdate != null ? Convert.ToDateTime(Scopelockdate) : DateTime.MinValue);
cmd.Parameters.AddWithValue("@ReleaseDate", ReleaseDate != null ? Convert.ToDateTime(ReleaseDate) : DateTime.MinValue);
cmd.Parameters.AddWithValue("@Segment", Segment);
cmd.Parameters.AddWithValue("@Query", Query);
cmd.Parameters.AddWithValue("@Stauts", Stauts != null ? Convert.ToInt32(Stauts) : 0);
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;
using Getqueuedetails.Models;
using Getqueuedetails.Controllers;
namespace GetData.Controllers
{
public class Default1Controller : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetData(string ReleaseId, string ReleaseName, string Scopelockdate, string ReleaseDate, string Segment, string Query, string Status)
{
List ObjClass = new List();
// MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
// con.Open();
// MySqlCommand cmd = new MySqlCommand();
// cmd.CommandText = "getReleaseDetails";
//cmd.CommandType = CommandType.StoredProcedure;
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM tfsperfqueue", con);
//MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//cmd.Dispose();
//con.Close();
{
public class Default1Controller : Controller
{
//
// GET: /Default1/
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetData(string ReleaseId, string ReleaseName, string Scopelockdate, string ReleaseDate, string Segment, string Query, string Status)
{
List
// MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
// con.Open();
// MySqlCommand cmd = new MySqlCommand();
// cmd.CommandText = "getReleaseDetails";
//cmd.CommandType = CommandType.StoredProcedure;
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM tfsperfqueue", con);
//MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
//DataSet ds = new DataSet();
//adp.Fill(ds);
//cmd.Dispose();
//con.Close();
//return Json(ObjClass, JsonRequestBehavior.AllowGet);
var model = new List();
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var release1 = new Release();
release1.ReleaseId = Convert.ToInt32(rdr["Release_Id"]);
release1.ReleaseName = Convert.ToString(rdr["Release_Name"]);
release1.Scopelockdate = Convert.ToDateTime(rdr["Scope_lock_date"]);
release1.Releasedate = Convert.ToDateTime(rdr["Release_Date"]);
release1.Segment = Convert.ToString(rdr["Segment"]);
release1.Query = Convert.ToString(rdr["Query"]);
release1.Status = Convert.ToInt32(rdr["Status"]);
model.Add(release1);
}
var model = new List
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
var release1 = new Release();
release1.ReleaseId = Convert.ToInt32(rdr["Release_Id"]);
release1.ReleaseName = Convert.ToString(rdr["Release_Name"]);
release1.Scopelockdate = Convert.ToDateTime(rdr["Scope_lock_date"]);
release1.Releasedate = Convert.ToDateTime(rdr["Release_Date"]);
release1.Segment = Convert.ToString(rdr["Segment"]);
release1.Query = Convert.ToString(rdr["Query"]);
release1.Status = Convert.ToInt32(rdr["Status"]);
model.Add(release1);
}
return Json(model, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult Save(string ReleaseId, string ReleaseName, string Scopelockdate, string ReleaseDate, string Segment, string Query, string Stauts)
{
public ActionResult Save(string ReleaseId, string ReleaseName, string Scopelockdate, string ReleaseDate, string Segment, string Query, string Stauts)
{
//int ReleaseId = Convert.ToInt32(Request.Form["ReleaseId"].ToString());
//string ReleaseName = Convert.ToString(Request.Form["ReleaseName"].ToString());
//DateTime Scopelockdate = Convert.ToDateTime(Request.Form["Scopelockdate"].ToString());
//DateTime ReleaseDate = Convert.ToDateTime(Request.Form["ReleaseDate"].ToString());
//string Segment = Convert.ToString(Request.Form["Segment"].ToString());
//string Query = Request.Form["Query"].ToString();
//int Stauts = Convert.ToInt16(Request.Form["Stauts"].ToString());
//string ReleaseName = Convert.ToString(Request.Form["ReleaseName"].ToString());
//DateTime Scopelockdate = Convert.ToDateTime(Request.Form["Scopelockdate"].ToString());
//DateTime ReleaseDate = Convert.ToDateTime(Request.Form["ReleaseDate"].ToString());
//string Segment = Convert.ToString(Request.Form["Segment"].ToString());
//string Query = Request.Form["Query"].ToString();
//int Stauts = Convert.ToInt16(Request.Form["Stauts"].ToString());
MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=prefautomationdb;password=Password@2");
con.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "sp_InsertReleasedetails";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "sp_InsertReleasedetails";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ReleaseId", ReleaseId != null ? Convert.ToInt32(ReleaseId) : 0);
cmd.Parameters.AddWithValue("@ReleaseName", ReleaseName);
cmd.Parameters.AddWithValue("@Scopelockdate", Scopelockdate != null ? Convert.ToDateTime(Scopelockdate) : DateTime.MinValue);
cmd.Parameters.AddWithValue("@ReleaseDate", ReleaseDate != null ? Convert.ToDateTime(ReleaseDate) : DateTime.MinValue);
cmd.Parameters.AddWithValue("@Segment", Segment);
cmd.Parameters.AddWithValue("@Query", Query);
cmd.Parameters.AddWithValue("@Stauts", Stauts != null ? Convert.ToInt32(Stauts) : 0);
cmd.ExecuteNonQuery();
con.Close();
RedirectToAction("Index");
return View();
}
}
}
con.Close();
RedirectToAction("Index");
return View();
}
}
}
This is index.cshtml
@{
ViewBag.Title = "Index";
}
ViewBag.Title = "Index";
}
| ReleaseId | ReleaseName | Scopelockdate | Releasedate | Segment | Query | Stauts |
|---|
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naveen BishtPosted Jul 14, 2017, 7:01 AM
Naveen BishtPosted Jul 14, 2017, 7:43 AM
Ranjitha MPosted Jul 14, 2017, 7:23 AM