Detail view of SQLCONNECTION, SQLDATAADAPTER and datatable all in one.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdoNet-SqlConnect-SqlAdapter.aspx.cs" Inherits="AdoNet_SqlConnect_SqlAdapter" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AdoNet_SqlConnect_SqlAdapter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string ConString = ConfigurationManager.ConnectionStrings["dbLearningConnectionString"].ToString() ;
SqlConnection con = new SqlConnection(ConString);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * From dbFriends", con);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
No comments:
Post a Comment