Retrieve (Get) data from Database using Web Mehthod in asp.net
Retrieve (Get) data from Database using Web Mehthod in asp.net
pagename.aspxpagename.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
public partial class Multiplefileuploader : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Getselect_tbl();
}
}
protected void UploadMultipleFiles(object sender, EventArgs e)
{
}
[WebMethod]
public static List
{
AdminLogin objAdminLogin = new AdminLogin();
DataTable objdt = new DataTable();
objdt = GetSelect("select AdminID,UserName,Password,LoginIP from tbl_Adminlogin");
List
for (int i = 0; i < objdt.Rows.Count; i++)
{
AdminLogin admin = new AdminLogin();
admin.AdminID = Convert.ToInt32(objdt.Rows[i]["AdminID"]);
admin.UserName = Convert.ToString(objdt.Rows[i]["UserName"]);
admin.Password = Convert.ToString(objdt.Rows[i]["Password"]);
admin.LoginIP = Convert.ToString(objdt.Rows[i]["LoginIP"]);
list.Add(admin);
}
return list;
}
[WebMethod]
public static DataTable GetSelect(string query)
{
SqlConnection objSqlConnection = new SqlConnection("Data Source=sumitshekhawat; Initial Catalog = db_sumit; User ID=sa; password=user@123");
SqlDataAdapter objadp = new SqlDataAdapter(query, objSqlConnection);
DataTable dt = new DataTable();
objadp.Fill(dt);
return dt;
}
}
public class AdminLogin
{
private int adminID;
private string userName;
private string password;
private string loginIP;
public int AdminID
{
get { return adminID; }
set { adminID = value;}
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string LoginIP
{
get { return loginIP; }
set { loginIP = value; }
}
}
function.js
$(document).ready(function () {
var type = "
Admin ID
User Name
Password
Login IP
";
$.ajax({
type: "post",
url: "Multiplefileuploader.aspx/Getselect_tbl",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
type += " " + data.d[i].AdminID + "
" + data.d[i].UserName + "
" + data.d[i].Password + "
" + data.d[i].LoginIP + "
";
}
type += "";
$("#tbl").append(type);
},
error: function (result) {
alert("Error");
},
complete: function (result) {
}
})
})
Comments
Post a Comment