Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Bind data to DataGrid using OleDbDataReader?

4 views
Skip to first unread message

zlata

unread,
Jun 27, 2002, 9:57:40 AM6/27/02
to
I'm looking for a faster way to bind data to my Web controls than DataSet
offers.

I have an 4 levels application but it works no enough quickly.

I tried to use OleDataReader, I put the next code on Data tier:

public OleDbDataReader GetDataQ() {

string sql;

sql = "SELECT * FROM MTABLE";

OleDbConnection dataConn = new OleDbConnection(MojaKonekcija);

OleDbDataReader dr;

dataConn.Open();

OleDbCommand myCommand = new OleDbCommand(sql, dataConn);

dr = myCommand.ExecuteReader();

rezultat.Close();

dr.Close();

dataConn.Close();

return dr;

}

I'd like to use "dr" and fill my DataGrid, but I've gor an error Data Reader
is closed.

What is a way reusing "dr" or to pass "dr" from one to another class?

On my client (odeBehind) I have:

OleDbDataReader rezultatVse = myList.GetDataQ();

but how to read them and hoe to bind to the DataGrid?

I would be helpfull if anybody has an example

Datagrid Girl

unread,
Jun 27, 2002, 4:12:06 PM6/27/02
to
You can't bind the Datagrid to your DataReader if it's already closed by the
time you pass it back, that's why you're getting that error.

I'm also surprised to hear that using a DataSet wasn't working fast enough
for you in this scenario. How big is MTable? Have you analyzed the indexes
on that table? That will gain you much more of a performance advantage than
simply switching from a DataSet to a DataReader. Also, are you truly using
a "Select *"? Is there a WHERE clause to your Sql statement?

Datagrid Girl

"zlata" <zl...@maop.si> wrote in message
news:O8Oy#JeHCHA.2572@tkmsftngp11...

Zlata Zlata

unread,
Jun 28, 2002, 9:54:09 AM6/28/02
to
Exactly, I have a problem using DataBind and User Controls at the same
time.
I have Menu user control, it would be nature Menu appears first, but I
don't know how. I must wait DataBound and when I see datas on my page, I
need about 8-9 seconds more to get Menu on the screen. What's happening
these 8-9 seconds, I don't know. Menu control returns me DHTML.
If I have a smaller amount of data I'm getting a Menu quicklier. What's
a way to forse User Control to release first and than Web Controls? Or
some other way to fix Menu on the top of the page.

Here is my code:
.aspx page:
<%@ Register TagPrefix="Portal" TagName="Meni" Src="Meni/VV_Meni.ascx"
%>
<%@ Page Language="c#" Inherits="Podpora.Pages.VV_NamVse"
Codebehind="VV_NamVse.aspx.cs" EnableSessionState="true"
AutoEventWireup="false" %>
<HTML><HEAD>
<PORTAL:MENI id="Meni" runat="server"></PORTAL:MENI>
<meta name="vs_showGrid" content="True">
<meta name="vs_targetSchema" content="HTML 4.0">
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<link rel="stylesheet" type="text/css" href="Style.css">
</HEAD>
<body>
<form runat="server" id="Form1">
<table><tr><td><p>
<asp:DataGrid id="MojGrid" CssClass="Grid" runat="server"
AllowSorting="True" OnSortCommand="OnSortCommandMojGrid"
DataKeyField="zap" AutoGenerateColumns="False" >
...
</asp:DataGrid></P></td></tr></table>
</form> ...<body></HTML>

VV_Meni.ascx user control:

<%@ Register TagPrefix="mintLab" Namespace="mintLab.webServerControls"
Assembly="mlcMenu" %>
<%@ Control Language="c#" %>
<tr><td>
<MINTLAB:CMENU id="CMenu1" runat="server" XmlDataFileName="MenuData.xml"
FontFamily="verdana" FontSize="8" FontBold="0" FontItalic="0"
TopMenuBGColor="FFFBF7" BGColor="FFFBF7" BGColorOver="B5BED6"
TopMenuBorderColor="636563" BorderColor="636563"
TopMenuFontColor="Black" FontColor="Black" TopMenuFontColorOver="Black"
FontColorOver="Black" MenuWidth="150" Left="1" Top="1"
SeparatorColor="FFFBF7" TopMenuIsHorizontal="true" IsHorizontal="false"
RightToLeft="false" DisplayOnClick="false"
TopMenuIsVariableWidth="false" IsVariableWidth="false"></MINTLAB:CMENU>
</td>
</tr>

Code behind:
..
ListeDB partnerMotnje = new ListeDB();
DataView rezultatVse = partnerMotnje.GetNamestitveVse(prefix,datum);
MojGrid.DataSource = rezultat;
MojGrid.DataBind();
..


Thank you for any help

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

David

unread,
Jun 28, 2002, 10:15:25 AM6/28/02
to
How about trying:
myDataGrid.DataSource = myCommand.ExecuteReader()
DataBind

Then - do you closings.
--
David Wier
http://aspexpress.com
Home of ASP Express - the best ASP text editor in the Galaxy
First editor with ASP.Net features

"zlata" <zl...@maop.si> wrote in message
news:O8Oy#JeHCHA.2572@tkmsftngp11...

0 new messages