3
Answers

fetching data from Db using link button

Harsha Eadara

Harsha Eadara

7y
207
1
 This is my Index.cshtml page
 
@{
ViewBag.Title = "Insert";
Layout = "";
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery-ui.min.js"></script>
<div>
<input type="button" class="btn" value="Admin" id="btntst"/>
</div>
<script>

$(document).ready(function () {
//function will be called on button click having id btnsave
$('#btntst').click(function(){

// debugger;
var frmdata = {
ReleaseId: $("#txtReleaseId").val(), //Reading text box values using Jquery
Release_Name: $("#txtRelease_Name").val(),
Scope_Lock_Date: $("#txtScope_Lock_Date").val(),
Release_Date: $("#txtReleaseDate").val(),
Segment: $("#txtSegment").val(),
Query: $("#txtQuery").val(),
Status: $("#txtStatus").val()
};
$.ajax({

type: "Get", //HTTP POST Method
url: '@Url.Action("Save","Home")', // Controller/View
//method: 'Post',
data: frmdata,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function () {
alert("save successfully");
//window.location.href = '/Default1/Insert';
},
error: function (error) {
alert(error)
}
});
});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
$("#txtScope_Lock_Date").datepicker();
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#txtRelease_Date").datepicker();
});
</script>
<br /><br />
<fieldset>
<div class="form-horizontal">
<div class="editor-label">
Release_Name
</div>
<div class="editor-label">
<input type="text" id="txtRelease_Name" />
</div>
<div class="editor-label">
Scope_Lock_Date
</div>
<div class="editor-label">
<input type="text" id="txtScope_Lock_Date" />
</div>
<div class="editor-label">
Release_Date
</div>
<div class="editor-label">
<input type="text" id="txtRelease_Date" />
</div>
<div class="editor-label">
Segment
</div>
<div class="editor-label">
<input type="text" id="txtSegment" />
</div>
<div class="editor-label">
Query
</div>
<div class="editor-label">
<input type="text" id="txtQuery" />
</div>
<div class="editor-label">
<br />
<input class="btn-default" type="button" id="btnSave" value="Save" />
</div>
</div>
</fieldset>
 
 This is my homecontroller.cs
 
 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 Link.Models;

namespace Link.Controllers
{
public class HomeController : Controller
{
public ActionResult Insert()
{
return View();
}

[HttpGet]
public ActionResult Save(string ReleaseID, string Release_Name, DateTime Scope_Lock_Date, DateTime Release_Date, string Segment, string Query, string Status)
{

MySqlConnection con = new MySqlConnection("server=localhost;user id=root;database=perfautomationdb;password=Password@1");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM tfsperfqueue",con);
// cmd.CommandText = "sp_InsertReleasedetails";
// DataTable DATA = new DataTable();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@ReleaseID", ReleaseID != null ? Convert.ToInt32(ReleaseID) : 0);
cmd.Parameters.AddWithValue("@Release_Name", Release_Name);
cmd.Parameters.AddWithValue("@Scope_Lock_Date", Scope_Lock_Date);
cmd.Parameters.AddWithValue("@Release_Date", Release_Date);
cmd.Parameters.AddWithValue("@Segment", Segment);
cmd.Parameters.AddWithValue("@Query", Query);
cmd.Parameters.AddWithValue("@Status", Status != null ? Convert.ToInt32(Status) : 0);
cmd.ExecuteNonQuery();
con.Close();
RedirectToAction("Insert");
return View();
}
}
}
 
i want to get data from DB if i click on Link button. 

Answers (3)