Newbie: problem posting

J

John Spiegel

Hi All,

I've got the following .aspx file with the then following .cs code. The
page renders fine on first run, but once I click the submit, it just comes
back with a cannot be displayed page indicating that the page is not
available. Anyone see what probably obvious or stupid thing I'm missing?

TIA,

John

Test.aspx:
========

<%@ Page Language="C#" Src="Temp.cs" Inherits="dgrdAccountSort" %>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:datagrid id="grdAccount" runat="server" Height="100%"
Width="100%"></asp:datagrid>
<input type="submit" value="Submit Query" runat="server" />
</form>
</body>
</html>


Temp.cs code:
==========
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public class dgrdAccountSort : Page
{
private string SortExpression;
protected DataGrid grdAccount;

protected void Page_Load(object Src, EventArgs e)
{
BindGridReader();
}


public void BindGridReader()
{
string SelectCommand = "SELECT * FROM AcctName";
if (SortExpression != null)
SelectCommand += " ORDER BY " + SortExpression;

OleDbConnection conn = new OleDbConnection(@"Provider=vfpoledb.1;User
Id=;Password=;Data
Source=C:\temp\dotnet1.1\asp\essentials\samples\mytesting\IntelligentOffice"
);
OleDbCommand cmd = new OleDbCommand( SelectCommand, conn );

conn.Open();
IDataReader reader = cmd.ExecuteReader();
grdAccount.DataSource = reader;
grdAccount.DataBind();

conn.Dispose();
}
}
 
S

S. Justin Gengo

John,

Instead of Connection.Dispose();

Use Connection.Close(); and then Connection.Dispose() instead.

Connection.Dispose() tells the .Net garbage collector that it's okay to
dispose of an object when it gets around to it. It does not close the
connection.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
R

Rick Spiewak

Just a thought - have you tried closing the connection by setting the
commandbehavior of your command to do so after the Datareader is closed. And
then close the datareader after binding?
 
S

S. Justin Gengo

John,

Sorry, but that was the only thing I could see that might have been wrong
with your code...

That said, I mostly program in VB.Net so maybe someone with more C#
experience could spot something else to try.

Good luck with it!

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
J

John Spiegel

Not yet, I'll give it a shot! I did find some very similar code code that
is working so I can use it to find my mistake. Thanks for the advice, Rick!

- John
 
J

John Spiegel

I appreciate the time looking into it! It's been a long time since I've
picked up a new language so now I'm trying to basically do two at once!
Yea! <g>
 
J

John Spiegel

FYI, As it turns out, the error seems to be tied to my not limiting the
amount of the table it displayed on the page. Once I narrowed it down to 20
rows at a time, the error went away. I'm not clear as to whether that's a
configurable limitation or not.

- John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top