Connecting Tech Pros Worldwide Help | Site Map

Datagrid record count

Peter W Johnson
Guest
 
Posts: n/a
#1: Mar 25 '06
Hi guys,

I have a problem with a datagrid record count. Here is the code:-

<snip>

Public Class frmMerchantDeposit
Inherits System.Windows.Forms.Form

Dim myconnection As New Odbc.OdbcConnection("DSN=database")
Dim dsMerchant As DataSet
Dim daMerchant As Odbc.OdbcDataAdapter

Private Sub frmMerchantDeposit_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load

myconnection.Open()
Dim mysql As String
mysql = "Select * from qryInvoice WHERE NOT Posted"
daMerchant = New Odbc.OdbcDataAdapter(mysql, myconnection)
dsMerchant = New DataSet
daMerchant.Fill(dsMerchant, "Merchant")

DataGridBatchMerchant.DataSource = dsMerchant.Tables("Merchant")
Dim tsMerchant As New DataGridTableStyle
tsMerchant.MappingName = "Merchant"
tsMerchant.AlternatingBackColor = System.Drawing.Color.Gold
DataGridBatchMerchant.TableStyles.Clear()

Dim cstbInvoiceDate As New DataGridTextBoxColumn
With cstbInvoiceDate
.MappingName = "InvoiceDate"
.HeaderText = "Date"
.Width = 80
End With

Dim cstbFirstName As New DataGridTextBoxColumn
With cstbFirstName
.MappingName = "FirstName"
.HeaderText = "First Name"
.Width = 150
End With

Dim cstbLastName As New DataGridTextBoxColumn
With cstbLastName
.MappingName = "LastName"
.HeaderText = "Last Name"
.Width = 150
End With

tsMerchant.GridColumnStyles.Add(cstbInvoiceDate)
tsMerchant.GridColumnStyles.Add(cstbFirstName)
tsMerchant.GridColumnStyles.Add(cstbLastName)

DataGridBatchMerchant.TableStyles.Add(tsMerchant)
DataGridBatchMerchant.Visible = True
lblRecordNumber.Text = "There are " &
dsMerchant.Tables(0).Rows.Count & " records in the table"
'...............first record count
myconnection.Close()

End Sub


Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

MsgBox("There are " & dsMerchant.Tables(0).Rows.Count & " records in
the table") '....................second record count
If dsMerchant.Tables(0).Rows.Count > 0 Then
'do stuff
End If

End Sub

End Class

</snip>

In the first record count in the .Load class I get zero records, the dataset
is empty. On the second I get a count of one but have not added any records.
Any ideas as to why?

Cheers

Peter.



Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Mar 27 '06

re: Datagrid record count


Hi,

You specify a name when filling the dataset. Try
dsMerchant.Tables("Merchant").Rows.Count

Ken
-----------------
"Peter W Johnson" <vk3eka@yahoo.com> wrote in message
news:uEJ0tsFUGHA.776@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi guys,
>
> I have a problem with a datagrid record count. Here is the code:-
>
> <snip>
>
> Public Class frmMerchantDeposit
> Inherits System.Windows.Forms.Form
>
> Dim myconnection As New Odbc.OdbcConnection("DSN=database")
> Dim dsMerchant As DataSet
> Dim daMerchant As Odbc.OdbcDataAdapter
>
> Private Sub frmMerchantDeposit_Load(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles MyBase.Load
>
> myconnection.Open()
> Dim mysql As String
> mysql = "Select * from qryInvoice WHERE NOT Posted"
> daMerchant = New Odbc.OdbcDataAdapter(mysql, myconnection)
> dsMerchant = New DataSet
> daMerchant.Fill(dsMerchant, "Merchant")
>
> DataGridBatchMerchant.DataSource = dsMerchant.Tables("Merchant")
> Dim tsMerchant As New DataGridTableStyle
> tsMerchant.MappingName = "Merchant"
> tsMerchant.AlternatingBackColor = System.Drawing.Color.Gold
> DataGridBatchMerchant.TableStyles.Clear()
>
> Dim cstbInvoiceDate As New DataGridTextBoxColumn
> With cstbInvoiceDate
> .MappingName = "InvoiceDate"
> .HeaderText = "Date"
> .Width = 80
> End With
>
> Dim cstbFirstName As New DataGridTextBoxColumn
> With cstbFirstName
> .MappingName = "FirstName"
> .HeaderText = "First Name"
> .Width = 150
> End With
>
> Dim cstbLastName As New DataGridTextBoxColumn
> With cstbLastName
> .MappingName = "LastName"
> .HeaderText = "Last Name"
> .Width = 150
> End With
>
> tsMerchant.GridColumnStyles.Add(cstbInvoiceDate)
> tsMerchant.GridColumnStyles.Add(cstbFirstName)
> tsMerchant.GridColumnStyles.Add(cstbLastName)
>
> DataGridBatchMerchant.TableStyles.Add(tsMerchant)
> DataGridBatchMerchant.Visible = True
> lblRecordNumber.Text = "There are " &
> dsMerchant.Tables(0).Rows.Count & " records in the table"
> '...............first record count
> myconnection.Close()
>
> End Sub
>
>
> Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnSave.Click
>
> MsgBox("There are " & dsMerchant.Tables(0).Rows.Count & " records
> in the table") '....................second record count
> If dsMerchant.Tables(0).Rows.Count > 0 Then
> 'do stuff
> End If
>
> End Sub
>
> End Class
>
> </snip>
>
> In the first record count in the .Load class I get zero records, the
> dataset is empty. On the second I get a count of one but have not added
> any records. Any ideas as to why?
>
> Cheers
>
> Peter.
>
>
>[/color]


Cor Ligthert [MVP]
Guest
 
Posts: n/a
#3: Mar 27 '06

re: Datagrid record count


Peter,

Is that happen as well as you eliminate all that style code.

(I do not see the sense here why you show that to us.)

Cor


Peter W Johnson
Guest
 
Posts: n/a
#4: Mar 28 '06

re: Datagrid record count


Cor,

I included it because I thought it may be relavant.

Cheers

Peter.


"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:OaVxOtVUGHA.776@TK2MSFTNGP09.phx.gbl...[color=blue]
> Peter,
>
> Is that happen as well as you eliminate all that style code.
>
> (I do not see the sense here why you show that to us.)
>
> Cor
>[/color]


Peter W Johnson
Guest
 
Posts: n/a
#5: Mar 28 '06

re: Datagrid record count


Ken,

Thanks but no difference.

Cheers

Peter.


"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:%23le%23tdVUGHA.4740@TK2MSFTNGP14.phx.gbl...[color=blue]
> Hi,
>
> You specify a name when filling the dataset. Try
> dsMerchant.Tables("Merchant").Rows.Count
>
> Ken
> -----------------
> "Peter W Johnson" <vk3eka@yahoo.com> wrote in message
> news:uEJ0tsFUGHA.776@TK2MSFTNGP09.phx.gbl...[color=green]
>> Hi guys,
>>
>> I have a problem with a datagrid record count. Here is the code:-
>>
>> <snip>
>>
>> Public Class frmMerchantDeposit
>> Inherits System.Windows.Forms.Form
>>
>> Dim myconnection As New Odbc.OdbcConnection("DSN=database")
>> Dim dsMerchant As DataSet
>> Dim daMerchant As Odbc.OdbcDataAdapter
>>
>> Private Sub frmMerchantDeposit_Load(ByVal sender As System.Object,
>> ByVal e As System.EventArgs) Handles MyBase.Load
>>
>> myconnection.Open()
>> Dim mysql As String
>> mysql = "Select * from qryInvoice WHERE NOT Posted"
>> daMerchant = New Odbc.OdbcDataAdapter(mysql, myconnection)
>> dsMerchant = New DataSet
>> daMerchant.Fill(dsMerchant, "Merchant")
>>
>> DataGridBatchMerchant.DataSource = dsMerchant.Tables("Merchant")
>> Dim tsMerchant As New DataGridTableStyle
>> tsMerchant.MappingName = "Merchant"
>> tsMerchant.AlternatingBackColor = System.Drawing.Color.Gold
>> DataGridBatchMerchant.TableStyles.Clear()
>>
>> Dim cstbInvoiceDate As New DataGridTextBoxColumn
>> With cstbInvoiceDate
>> .MappingName = "InvoiceDate"
>> .HeaderText = "Date"
>> .Width = 80
>> End With
>>
>> Dim cstbFirstName As New DataGridTextBoxColumn
>> With cstbFirstName
>> .MappingName = "FirstName"
>> .HeaderText = "First Name"
>> .Width = 150
>> End With
>>
>> Dim cstbLastName As New DataGridTextBoxColumn
>> With cstbLastName
>> .MappingName = "LastName"
>> .HeaderText = "Last Name"
>> .Width = 150
>> End With
>>
>> tsMerchant.GridColumnStyles.Add(cstbInvoiceDate)
>> tsMerchant.GridColumnStyles.Add(cstbFirstName)
>> tsMerchant.GridColumnStyles.Add(cstbLastName)
>>
>> DataGridBatchMerchant.TableStyles.Add(tsMerchant)
>> DataGridBatchMerchant.Visible = True
>> lblRecordNumber.Text = "There are " &
>> dsMerchant.Tables(0).Rows.Count & " records in the table"
>> '...............first record count
>> myconnection.Close()
>>
>> End Sub
>>
>>
>> Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles btnSave.Click
>>
>> MsgBox("There are " & dsMerchant.Tables(0).Rows.Count & " records
>> in the table") '....................second record count
>> If dsMerchant.Tables(0).Rows.Count > 0 Then
>> 'do stuff
>> End If
>>
>> End Sub
>>
>> End Class
>>
>> </snip>
>>
>> In the first record count in the .Load class I get zero records, the
>> dataset is empty. On the second I get a count of one but have not added
>> any records. Any ideas as to why?
>>
>> Cheers
>>
>> Peter.
>>
>>
>>[/color]
>
>[/color]


Closed Thread