I am setting up a custom tab where users can view and edit data. I need to establish a trusted SQL connection and have the data displayed in a grid view.
Should I build a console or web app?
I have provided my .aspx and aspx.cs files below.
I get the error message below while running it:
“Error: Make sure that the class defined in this code file matches the
‘inherits’ attribute, and that it extends the correct base class (e.g.
Page or UserControl)”.
Here is my Default.aspx code:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
</form>
</body>
</html>
Here is my Default.aspx.cs code:
///<summary>
///Demonstrates how to work with SqlConnection objects
///</summary>
class SqlConnectionDemo
{
static void Main()
{
// 1. Instantiate the connection
SqlConnectionconn = newSqlConnection("Data Source=TestDB;Initial Catalog=Impresario;Integrated Security=SSPI");
SqlDataReaderrdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommandcmd = newSqlCommand("select * from LT_WEB_DONATIONS_EXTRA_INFO_TEMP", conn);
//
// 4. Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
// close the reader
if(rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if(conn != null)
{
conn.Close();
}
}
}
}
Your code-behind page must inherit from
System.Web.UI.Page, like so: