April 10, 2015 07:46 by
Peter
ASP.NET will gives you adaptability by they way you connect with databases. It would be ideal if you include the following code in your aspx page and check how to get connection on .aspx page. And here is the code that I used:
<%@ 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>
HostForLIFE.eu ASP.NET 5 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.