|
-
May 21st, 2003, 08:15 AM
#1
Thread Starter
Hyperactive Member
Reading all rows in a column of a dataset
I have loaded the contents of an XML file into a dataset, and then into a datagrid.
But I am stuck with this (probably simple thing),
How do you read data from a specific field / column, or find out how many records / rows exist, in preferably the dataset. But if not possible, in the datagrid.
Thanks in advance for any help you can offer.
Code:
Dim d As New DataSet()
Try
d.ReadXml("C:\test.xml")
Me.DataGrid1.DataSource = d
Catch exp As Exception
MessageBox.Show(exp.Message.ToString, "Exception was caught", MessageBoxButtons.OK)
End Try
ds = d.Copy
DataGrid1.DataSource = ds
DataGrid1.Refresh()
d.Dispose()
-
May 21st, 2003, 08:36 AM
#2
Hyperactive Member
To find how many rows there are: ds.tables("mytable").rows.count
To read from a particular column: ds.tables("mytable").rows(r)(c)
where r is the row 0 based, and c is the column 0 based.
Learn, this is the Keyword...
-
May 21st, 2003, 08:38 AM
#3
Thread Starter
Hyperactive Member
-
May 21st, 2003, 08:48 AM
#4
Hyperactive Member
Learn, this is the Keyword...
-
May 21st, 2003, 09:21 AM
#5
Thread Starter
Hyperactive Member
When using it, I am getting the error:
An unhandled exception of type 'System.InvalidCastException' occurred in myClient.exe
Code:
Dim a As Integer
a = Me.ListBox1.SelectedIndex
Me.lblFullName = ds.Tables("person").Rows(a)(0) << ERROR at this line
Me.lblFirstName = ds.Tables("person").Rows(a)("firstName")
Me.lblDOB = ds.Tables("person").Rows(a)("birth")
Me.lblFax = ds.Tables("person").Rows(a)("fax")
Me.lblMobile = ds.Tables("person").Rows(a)("mobile")
Me.lblMSN = ds.Tables("person").Rows(a)("msn")
Me.lblSurname = ds.Tables("person").Rows(a)("surname")
Me.lblTelNo = ds.Tables("person").Rows(a)("tel")
Me.lblWebsite = ds.Tables("person").Rows(a)("website")
Me.lblWork = ds.Tables("person").Rows(a)("work")
Me.txtNotes = ds.Tables("person").Rows(a)("notes")
integer a, appears to be a valid number, that should exist, so anyone any ideas?
-
May 21st, 2003, 09:32 AM
#6
Hyperactive Member
When no items are selected, listbox.selectedindex equals -1.Try to see if a=-1
Learn, this is the Keyword...
-
May 21st, 2003, 09:32 AM
#7
Thread Starter
Hyperactive Member
solved it, forgot the .text
-
May 21st, 2003, 09:35 AM
#8
Sleep mode
This will returns number of rows in database .
VB Code:
Public Function Nu_of_Rows(ByVal TableStr As String) As Integer
Dim SqlStr As String = "Select * FROM " & TableStr
Dim ds As New DataSet()
Dim adp As New OleDbDataAdapter(SqlStr, MyConnection)
adp.Fill(ds, TableStr)
Return ds.Tables(TableStr).Rows.Count
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|