PC Review


Reply
Thread Tools Rate Thread

count rows of a DataGrid ?

 
 
Thomas P.
Guest
Posts: n/a
 
      13th Nov 2003
Hi,

I used VB.NET 2003 to read data from a SqlCe database and show it in a
DataGrid.
Now I am looking for a method which returns an integer value with the
total number of rows and/or colums to me.

Dim cn As SqlCeConnection
cn = New SqlCeConnection("Data Source = \My
Documents\Test.sdf;Password=")
cn.Open()
Dim cmd As SqlCeCommand = cn.CreateCommand
cmd.CommandText = "Select numbers From Test"
Dim da As New SqlCeDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.Enabled = False
DataGrid1.DataSource = ds.Tables(0)

I need to know how many rows the DataGrid1 has because I want to use a
loop to go through the DataGrid.
With the following code I plan to read some datas.

ds.Tables(0).Rows(0)(0)

I am a newbee in VB.Net so please try to explain it with simple words
and some code samples to me. Thans a lot.

Regards,

Thomas Peterson
 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      13th Nov 2003
What you need to do is determine the number of rows belonging to the
datasource itself (in this case a DataTable). For example

ds.Tables(0).Rows.Count

Will give you the number of rows contained in the table.

Likewise if you want the number of columns, you can use the Count property
of the Columns collection:-

ds.Tables(0).Columns.Count

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Thomas P." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I used VB.NET 2003 to read data from a SqlCe database and show it in a
> DataGrid.
> Now I am looking for a method which returns an integer value with the
> total number of rows and/or colums to me.
>
> Dim cn As SqlCeConnection
> cn = New SqlCeConnection("Data Source = \My
> Documents\Test.sdf;Password=")
> cn.Open()
> Dim cmd As SqlCeCommand = cn.CreateCommand
> cmd.CommandText = "Select numbers From Test"
> Dim da As New SqlCeDataAdapter(cmd)
> Dim ds As New DataSet
> da.Fill(ds)
> DataGrid1.Enabled = False
> DataGrid1.DataSource = ds.Tables(0)
>
> I need to know how many rows the DataGrid1 has because I want to use a
> loop to go through the DataGrid.
> With the following code I plan to read some datas.
>
> ds.Tables(0).Rows(0)(0)
>
> I am a newbee in VB.Net so please try to explain it with simple words
> and some code samples to me. Thans a lot.
>
> Regards,
>
> Thomas Peterson



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      13th Nov 2003
Or, if you bound the datagrid to the DataView, use DataView.Count

"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What you need to do is determine the number of rows belonging to the
> datasource itself (in this case a DataTable). For example
>
> ds.Tables(0).Rows.Count
>
> Will give you the number of rows contained in the table.
>
> Likewise if you want the number of columns, you can use the Count property
> of the Columns collection:-
>
> ds.Tables(0).Columns.Count
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Thomas P." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I used VB.NET 2003 to read data from a SqlCe database and show it in a
> > DataGrid.
> > Now I am looking for a method which returns an integer value with the
> > total number of rows and/or colums to me.
> >
> > Dim cn As SqlCeConnection
> > cn = New SqlCeConnection("Data Source = \My
> > Documents\Test.sdf;Password=")
> > cn.Open()
> > Dim cmd As SqlCeCommand = cn.CreateCommand
> > cmd.CommandText = "Select numbers From Test"
> > Dim da As New SqlCeDataAdapter(cmd)
> > Dim ds As New DataSet
> > da.Fill(ds)
> > DataGrid1.Enabled = False
> > DataGrid1.DataSource = ds.Tables(0)
> >
> > I need to know how many rows the DataGrid1 has because I want to use a
> > loop to go through the DataGrid.
> > With the following code I plan to read some datas.
> >
> > ds.Tables(0).Rows(0)(0)
> >
> > I am a newbee in VB.Net so please try to explain it with simple words
> > and some code samples to me. Thans a lot.
> >
> > Regards,
> >
> > Thomas Peterson

>
>



 
Reply With Quote
 
Thomas P.
Guest
Posts: n/a
 
      14th Nov 2003
Thank you, this works fine now.

Thomas


"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> What you need to do is determine the number of rows belonging to the
> datasource itself (in this case a DataTable). For example
>
> ds.Tables(0).Rows.Count
>
> Will give you the number of rows contained in the table.
>
> Likewise if you want the number of columns, you can use the Count property
> of the Columns collection:-
>
> ds.Tables(0).Columns.Count
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Thomas P." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> >
> > I used VB.NET 2003 to read data from a SqlCe database and show it in a
> > DataGrid.
> > Now I am looking for a method which returns an integer value with the
> > total number of rows and/or colums to me.
> >
> > Dim cn As SqlCeConnection
> > cn = New SqlCeConnection("Data Source = \My
> > Documents\Test.sdf;Password=")
> > cn.Open()
> > Dim cmd As SqlCeCommand = cn.CreateCommand
> > cmd.CommandText = "Select numbers From Test"
> > Dim da As New SqlCeDataAdapter(cmd)
> > Dim ds As New DataSet
> > da.Fill(ds)
> > DataGrid1.Enabled = False
> > DataGrid1.DataSource = ds.Tables(0)
> >
> > I need to know how many rows the DataGrid1 has because I want to use a
> > loop to go through the DataGrid.
> > With the following code I plan to read some datas.
> >
> > ds.Tables(0).Rows(0)(0)
> >
> > I am a newbee in VB.Net so please try to explain it with simple words
> > and some code samples to me. Thans a lot.
> >
> > Regards,
> >
> > Thomas Peterson

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Getting the count of Currently viewable rows in a datagrid ntregillus@gmail.com Microsoft Dot NET Framework Forms 1 2nd Aug 2006 07:44 PM
How to count total number of rows in the datagrid. =?Utf-8?B?cGF0YW5n?= Microsoft VB .NET 2 31st Mar 2005 07:41 AM
How to get the rows count from datagrid??? Jet Leung Microsoft C# .NET 3 29th Nov 2004 09:17 PM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 Microsoft ASP .NET 2 6th Jun 2004 08:16 AM
Where is DataGrid.Rows.Count ? Fred Morrison Microsoft VB .NET 1 11th Jan 2004 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 PM.