Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid problem

Reply
Thread Tools

DataGrid problem

 
 
Swandi Candra
Guest
Posts: n/a
 
      08-06-2003
Folks,

I found the following example from dotnetjunkies, which worked
fine.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<head>
<title>ASPNextGen.com - Paging in the DataGrid Part 1</title>
<script runat="server" language="VB">
Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim ds As New DataSet
Dim dsc As SQLDataAdapter
Dim strSQL As String
Dim strCon As String

strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pw d=;"

dsc = New SQLDataSetCommand(strSQL, strCon)
dsc.Fill(Ds, "Customers")

myDataGrid.DataSource = ds.Tables("Customers").DefaultView
myDataGrid.DataBind()
End Sub

Sub myDataGrid_PageChanger(Source As Object, _
E As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = E.NewPageIndex
BindData()
End Sub
</script>
<style>
.DataGrid {font-small Verdana, Arial, sans-serif}
</style>
</head>

<body>
<form runat="server" method="post">
<aspataGrid runat="server" id="myDataGrid"
Border="0"
Cellpadding="4"
Cellspacing="0"
AlternatingItemStyle-BackColor="#EFEFEF"
ShowHeader="True"
CssClass="DataGrid"
HeaderStyle-BackColor="Black"
HeaderStyle-ForeColor="White"
HeaderStyle-Font-Bold="True"
AllowPaging="True"
PageSize="10"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="myDataGrid_PageChanger"
/>
</form>
</body>
</html>

However, it used SqlClient as its provider, instead of OleDb.
Therefore, I changed the binding part as follow

Sub BindData()
Dim conn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim strSQL As String
Dim strCon As String

strSQL = "SELECT CompanyName, ContactName, " & _
" ContactTitle, Phone, Fax FROM Customers " & _
" ORDER BY CompanyName"
strCon = "server=localhost;database=Northwind;uid=sa;pw d=;"

conn = New OleDbConnection(strCon)
conn.open

cmd = new OleDbCommand()
cmd.Connection = conn
cmd.CommandText = strSQL

myDataGrid.DataSource = cmd.ExecuteReader()
myDataGrid.DataBind()
End Sub

When I ran it, the ASP.NET displayed an error indicating that
I should include AllowCustomPaging=True property in aspataGrid.
After I added it, the list can be displayed property, except with
no paging.

Does anyone know what's going on?
Can anyone suggest me, how to do it properly with OleDb provider?

Thanks for your help.
SC
 
Reply With Quote
 
 
 
 
Swandi Candra
Guest
Posts: n/a
 
      08-07-2003
Jos,

I think, you missed my points.
Please read it carefully again.

What I'm asking is, how can use OleDB provider
for DataGrid's data source. I don't want to use
SqlConnection as it will prevent you from use
non Microsoft SQL Server database.


> Swandi Candra wrote:
> > Folks,

> <cut>
> > However, it used SqlClient as its provider, instead of OleDb.
> > Therefore, I changed the binding part as follow
> >
> > Sub BindData()
> > Dim conn As OleDbConnection
> > Dim cmd As OleDbCommand
> > Dim dr As OleDbDataReader

> <etc...>
> > When I ran it, the ASP.NET displayed an error indicating that
> > I should include AllowCustomPaging=True property in aspataGrid.
> > After I added it, the list can be displayed property, except with
> > no paging.
> >
> > Does anyone know what's going on?
> > Can anyone suggest me, how to do it properly with OleDb provider?
> >
> > Thanks for your help.
> > SC

>
> You have to change ALL the OleDb's into Sql's
> OleDbConnection -> SqlConnection
> OleDbCommand -> SqlCommand
> etc...
>
> Also change your imports accordingly (System.Data.Sql instead of
> System.Data.OleDb).

 
Reply With Quote
 
 
 
 
Prasad
Guest
Posts: n/a
 
      08-07-2003
Hi

DataReader does not support Automatic Paging. That's why it is throwing
error. Use OleDbAdapter and Dataset as in the Example and it will work.

HTH
Prasad

"Swandi Candra" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Jos,
>
> I think, you missed my points.
> Please read it carefully again.
>
> What I'm asking is, how can use OleDB provider
> for DataGrid's data source. I don't want to use
> SqlConnection as it will prevent you from use
> non Microsoft SQL Server database.
>
>
> > Swandi Candra wrote:
> > > Folks,

> > <cut>
> > > However, it used SqlClient as its provider, instead of OleDb.
> > > Therefore, I changed the binding part as follow
> > >
> > > Sub BindData()
> > > Dim conn As OleDbConnection
> > > Dim cmd As OleDbCommand
> > > Dim dr As OleDbDataReader

> > <etc...>
> > > When I ran it, the ASP.NET displayed an error indicating that
> > > I should include AllowCustomPaging=True property in aspataGrid.
> > > After I added it, the list can be displayed property, except with
> > > no paging.
> > >
> > > Does anyone know what's going on?
> > > Can anyone suggest me, how to do it properly with OleDb provider?
> > >
> > > Thanks for your help.
> > > SC

> >
> > You have to change ALL the OleDb's into Sql's
> > OleDbConnection -> SqlConnection
> > OleDbCommand -> SqlCommand
> > etc...
> >
> > Also change your imports accordingly (System.Data.Sql instead of
> > System.Data.OleDb).



 
Reply With Quote
 
Leonard
Guest
Posts: n/a
 
      08-10-2003

Oh,yes. To use OLEDB you have to use the OleDbDataReader
class instead of SqlDataReader, of course.

>-----Original Message-----
>Jos,
>
>You can use the DataReader and with paging as follows:
>
> // the DataGrid is dg
> SqlConnection connObject;
> SqlCommand cmdObject;
> SqlDataReader rdr;
>
> connObject.ConnectionString = "[whatever]";
> connObject.Open();
> string strCMD = "Select count(on some column like the
>PK) as nbrRows FROM [your table or whatever]";
> cmdObject = new SqlCommand(strCMD, connObject);
> cmdObject.CommandType = CommandType.Text;
> rdr = cmdObject.ExecuteReader();
> if (!rdrDocs.HasRows)
> throw new [Your app exception - catch it below];
> rdr.Read();
> int nbr = Convert.ToInt32(rdrDocs["nbrRows"]);
> rdr.Close();
>
> strCMD = "SELECT [your projection] FROM [your table or
>whatever]";
> cmdObject.CommandText = strCMD;
>
> rdr = cmdObject.ExecuteReader();
> if (!rdr.HasRows)
> throw new [Your app exception - catch it below];
>
> dg.DataSource = rdr;
> dg.VirtualItemCount = nbr; // This sets the number of
>rows in grid
> dg.DataBind();
> rdr.Close();
>
>This works for the Sql... variety. I haven't tried it
>with the OleDb... flavor, but I assume it works. Try it
>and let us know.
>
>>-----Original Message-----
>>Hi
>>
>>DataReader does not support Automatic Paging. That's why

>it is throwing
>>error. Use OleDbAdapter and Dataset as in the Example

and
>it will work.
>>
>>HTH
>>Prasad
>>
>>"Swandi Candra" <(E-Mail Removed)> wrote in

>message
>>news:(E-Mail Removed) .com...
>>> Jos,
>>>
>>> I think, you missed my points.
>>> Please read it carefully again.
>>>
>>> What I'm asking is, how can use OleDB provider
>>> for DataGrid's data source. I don't want to use
>>> SqlConnection as it will prevent you from use
>>> non Microsoft SQL Server database.
>>>
>>>
>>> > Swandi Candra wrote:
>>> > > Folks,
>>> > <cut>
>>> > > However, it used SqlClient as its provider,

instead
>of OleDb.
>>> > > Therefore, I changed the binding part as follow
>>> > >
>>> > > Sub BindData()
>>> > > Dim conn As OleDbConnection
>>> > > Dim cmd As OleDbCommand
>>> > > Dim dr As OleDbDataReader
>>> > <etc...>
>>> > > When I ran it, the ASP.NET displayed an error

>indicating that
>>> > > I should include AllowCustomPaging=True property

in
>aspataGrid.
>>> > > After I added it, the list can be displayed

>property, except with
>>> > > no paging.
>>> > >
>>> > > Does anyone know what's going on?
>>> > > Can anyone suggest me, how to do it properly with

>OleDb provider?
>>> > >
>>> > > Thanks for your help.
>>> > > SC
>>> >
>>> > You have to change ALL the OleDb's into Sql's
>>> > OleDbConnection -> SqlConnection
>>> > OleDbCommand -> SqlCommand
>>> > etc...
>>> >
>>> > Also change your imports accordingly

(System.Data.Sql
>instead of
>>> > System.Data.OleDb).

>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in nesting datagrid in to a nested datagrid sajvargs ASP .Net 0 02-20-2005 12:17 AM
problema ultima pagina datagrid asp.net/problem last page datagrid roberto ASP .Net Datagrid Control 1 02-17-2005 07:50 AM
DataGrid edited values problem and autogenerated columns in DataGrid problem John Walsch ASP .Net Web Controls 0 07-09-2004 03:03 PM
Call Datagrid Command column outside datagrid Dave ASP .Net 0 11-20-2003 11:11 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments