On page connection in asp.net with c#

On page connection in asp.net with c#:



ASP.NET gives you flexibility in how you connect to databases. please add the follwoing code in you aspx page and check how to get connection on .aspx page.


Connection in asp.net  in .aspx page with c#


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="onpageconnection.aspx.cs" Inherits="onpageconnection" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Data" %>

<script  runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            System.Data.SqlClient.SqlConnection con;
            sqlconn objconn = new sqlconn();
            con = objconn.getcon();
            con.Open();
            String str = "select * from EmpDemo";
            //SqlCommand cmd = new SqlCommand(str,con);
            //SqlDataReader adp;
            SqlDataAdapter adp = new SqlDataAdapter(str,con);
            
            DataSet ds = new DataSet();
            adp.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
            //Response.Write("connection open!!!!!!!");
        }
        catch (Exception ex)
        {

            Response.Write(ex.Message);
        }


    }
</script>

<html>
<head>
<title></title>
</head>

<body>

<form id="Form1" runat="server">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</form>

</body>
</html>


Other Crystal Report related Post:


Here we give the list of Examples related to gridview:


Comments