473,245 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

Dataset - Please read, am I using the right object?

Hi,

Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB.

I have a problem to read/parse the dataset and I would like to know if I
am using the right object to reach my goal. And I don't want to spend
hours to find out, would you tell me if I'm going in the wrong path?

Private dbConnector As New OleDbConnection

Private Function mySQL() as dataset
Dim strSQLSelect As String

strSQLSelect = "SELECT strName" & _
"FROM tblAdmin " & _
"ORDER BY ID ASC;"

Dim dstDataset As DataSet = New DataSet
Dim Cmd As New OleDbDataAdapter(strSQLSelect, dbConnector)
Cmd.Fill(dstDataset)

Return dstDataset
End Function

Private Sub fillComboBoxAdmin()
Dim dstDataset As DataSet
dstDataset = mySQL()
Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next
End Sub

Then the combobox is filled. The user can select a row in the combo box
and if the user hit the "Save" button. Another part of the code will
save the selected combobox row to the database for current user.

Am I doing a good use of the dataset? Because in the sub
fillComboBoxAdmin, I can't get anything out of the dataset.

Thanks
Marty







Jul 21 '05 #1
7 1770
Hi Marty,

You might not be getting any data into your dataset. You should put the
data code in a try catch block.

Try
....database code
Catch exc as Exception
msgbox(exc.Message)
End Try

On thing I notice is that in the first line of your Select statement it
doesn't look like there is a space between strName and the ". Putting a
space there might return some data for you. Also changing the loop in your
fill function should help. Remove these lines:
Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next
And Add:

Dim objDR as DataRow
For Each objDR in dstDataset.Tables(0).Rows
cbxAdmin.Items.Add(cstr(objdr("strName")))
Next

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
"Marty" <ma**@to.forum> wrote in message
news:P1***************@fe51.usenetserver.com... Hi,

Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB.
I have a problem to read/parse the dataset and I would like to know if I
am using the right object to reach my goal. And I don't want to spend
hours to find out, would you tell me if I'm going in the wrong path?

Private dbConnector As New OleDbConnection

Private Function mySQL() as dataset
Dim strSQLSelect As String

strSQLSelect = "SELECT strName" & _
"FROM tblAdmin " & _
"ORDER BY ID ASC;"

Dim dstDataset As DataSet = New DataSet
Dim Cmd As New OleDbDataAdapter(strSQLSelect, dbConnector)
Cmd.Fill(dstDataset)

Return dstDataset
End Function

Private Sub fillComboBoxAdmin()
Dim dstDataset As DataSet
dstDataset = mySQL()
Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next
End Sub

Then the combobox is filled. The user can select a row in the combo box
and if the user hit the "Save" button. Another part of the code will
save the selected combobox row to the database for current user.

Am I doing a good use of the dataset? Because in the sub
fillComboBoxAdmin, I can't get anything out of the dataset.

Thanks
Marty






Jul 21 '05 #2
Thanks Ken,

With your tips I get my combobox filled with coherent data.
Thank you, you helped me a lot.

Marty

Ken Dopierala Jr. wrote:
Hi Marty,

You might not be getting any data into your dataset. You should put the
data code in a try catch block.

Try
...database code
Catch exc as Exception
msgbox(exc.Message)
End Try

On thing I notice is that in the first line of your Select statement it
doesn't look like there is a space between strName and the ". Putting a
space there might return some data for you. Also changing the loop in your
fill function should help. Remove these lines:

Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next

And Add:

Dim objDR as DataRow
For Each objDR in dstDataset.Tables(0).Rows
cbxAdmin.Items.Add(cstr(objdr("strName")))
Next

Good luck! Ken.

Jul 21 '05 #3
I'm wondering why you are manually filling the list for the combobow when
you could just as easily set the datasource and displaymember properties of
the combobox and have it bound directly to the datatable.
"Marty" <ma**@to.forum> wrote in message
news:_G****************@fe51.usenetserver.com...
Thanks Ken,

With your tips I get my combobox filled with coherent data.
Thank you, you helped me a lot.

Marty

Ken Dopierala Jr. wrote:
Hi Marty,

You might not be getting any data into your dataset. You should put the
data code in a try catch block.

Try
...database code
Catch exc as Exception
msgbox(exc.Message)
End Try

On thing I notice is that in the first line of your Select statement it
doesn't look like there is a space between strName and the ". Putting a
space there might return some data for you. Also changing the loop in your fill function should help. Remove these lines:

Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next

And Add:

Dim objDR as DataRow
For Each objDR in dstDataset.Tables(0).Rows
cbxAdmin.Items.Add(cstr(objdr("strName")))
Next

Good luck! Ken.


Jul 21 '05 #4
Mary,

As addition to the message from Ken (D) and Stephany when you do not know
it.
(In the shortest notation), you can change this Sub in this way)

\\\
Private Sub fillComboBoxAdmin()
cbxAdmin.datasource = mySQL()
cbxAdmin.displaymember = "TheColumName"
End sub
///
Your current routine should give an error (as Ken showed as well), the
reason is because you are looping through the rows while using everytime the
next item. Which should when you have more rows than items give an error and
probably always give a not wanted result.

I hope this helps?

Cor
Jul 21 '05 #5
Hi Stephany,

Good point, it thaught to that but I wans't sure about which way is
better. It start form this point:

1- I could implement my code in way you told me. That mean that when
the user select a row in the combobox and save, the code would have to
search fisrt the unique number (ID in DB table) of the selected item in
the combobox, then save the unique number (ID) for the current user (in
DB user table).

2- Implement the way I did and insert all items in the combobox ordered
by unique number (ID) from the SQL query. So I would know directly
which unique number (ID) to write (for the selected item) for current
user (in DB user table).

This is the first time that I build a data management application. I do
it as a personal project. I'll take your tip in consideration, because
writing it down make me think about it again and I think that point#1
should be better for data integrity. But it need one more access to DB
to have this unique number.

Am I right?

Thanks very much.

Marty

Stephany Young wrote:
I'm wondering why you are manually filling the list for the combobow when
you could just as easily set the datasource and displaymember properties of
the combobox and have it bound directly to the datatable.
"Marty" <ma**@to.forum> wrote in message
news:_G****************@fe51.usenetserver.com...
Thanks Ken,

With your tips I get my combobox filled with coherent data.
Thank you, you helped me a lot.

Marty

Ken Dopierala Jr. wrote:
Hi Marty,

You might not be getting any data into your dataset. You should put the
data code in a try catch block.

Try
...database code
Catch exc as Exception
msgbox(exc.Message)
End Try

On thing I notice is that in the first line of your Select statement it
doesn't look like there is a space between strName and the ". Putting a
space there might return some data for you. Also changing the loop in
your
fill function should help. Remove these lines:

Dim i As Int32
For i = 0 To dstDataset.Tables(0).Rows.Count - 1
'Fill combobox with dataset content
cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
Next
And Add:

Dim objDR as DataRow
For Each objDR in dstDataset.Tables(0).Rows
cbxAdmin.Items.Add(cstr(objdr("strName")))
Next

Good luck! Ken.



Jul 21 '05 #6
Hi Cor,

I tried it but I get the combobox filled with
"System.Data.DataViewManagerListItemTypeDescriptor "

I have to leave, but I'll double check my code when I'll be back!

Thanks for your help.

Marty

Cor Ligthert wrote:
Mary,

As addition to the message from Ken (D) and Stephany when you do not know
it.
(In the shortest notation), you can change this Sub in this way)

\\\
Private Sub fillComboBoxAdmin()
cbxAdmin.datasource = mySQL()
cbxAdmin.displaymember = "TheColumName"
End sub
///
Your current routine should give an error (as Ken showed as well), the
reason is because you are looping through the rows while using everytime the
next item. Which should when you have more rows than items give an error and
probably always give a not wanted result.

I hope this helps?

Cor

Jul 21 '05 #7
To get the idea of how to achieve this I would recommend that you use the
form designer to do the initial coding work for you.

Drop an OleDbDataAdapter component on the form and configure it to do your
SQL SELECT and to create a Typed Dataset for your project. This should also
add an OleDbConnection component and a Dataset component to your form. (Just
follow your nose in configuring these components.)

Drop a Dataviw component on the form and connect it to the Datatable in your
Dataset. Set the Sort property of the dataview to ID.

For your ComboBox, set the DataSource property to <DataViewname>, set the
DisplayMember property to strName ans set the ValueMember property to ID.

In the Form_Load event, add:

<OleDbDataAdaptername>.Fill(<DataSetname>.Tables(" <DataTablename>"))

In the <comboboxname>_SelectedValueChanged event, add the code to deal with
the users selection by accessing the SelectedValue property of the ComboBox
which will be the ID (ValueMember) of the selected row.

Dim _i As Integer = cbxAdmin.SelectedValue

' Deal with _i as required

Once you have been through this exercise, I would recommend that you inspect
the generated code to gain an understanding of what is actually happening.
If you so wish, you could use that code as the basis for coding it yourself
rather than using the designer components.

I further recommend that you peruse the help files for the
componets/properties/methods mentioned above so that you gain a better
understanding of how (in this case) the ComboBox is designed to be
integrated with the various data components.
"Marty" <ma**@to.forum> wrote in message
news:zN****************@fe51.usenetserver.com...
Hi Stephany,

Good point, it thaught to that but I wans't sure about which way is
better. It start form this point:

1- I could implement my code in way you told me. That mean that when
the user select a row in the combobox and save, the code would have to
search fisrt the unique number (ID in DB table) of the selected item in
the combobox, then save the unique number (ID) for the current user (in
DB user table).

2- Implement the way I did and insert all items in the combobox ordered
by unique number (ID) from the SQL query. So I would know directly
which unique number (ID) to write (for the selected item) for current
user (in DB user table).

This is the first time that I build a data management application. I do
it as a personal project. I'll take your tip in consideration, because
writing it down make me think about it again and I think that point#1
should be better for data integrity. But it need one more access to DB
to have this unique number.

Am I right?

Thanks very much.

Marty

Stephany Young wrote:
I'm wondering why you are manually filling the list for the combobow when you could just as easily set the datasource and displaymember properties of the combobox and have it bound directly to the datatable.
"Marty" <ma**@to.forum> wrote in message
news:_G****************@fe51.usenetserver.com...
Thanks Ken,

With your tips I get my combobox filled with coherent data.
Thank you, you helped me a lot.

Marty

Ken Dopierala Jr. wrote:

Hi Marty,

You might not be getting any data into your dataset. You should put thedata code in a try catch block.

Try
...database code
Catch exc as Exception
msgbox(exc.Message)
End Try

On thing I notice is that in the first line of your Select statement it
doesn't look like there is a space between strName and the ". Putting aspace there might return some data for you. Also changing the loop in


your
fill function should help. Remove these lines:

> Dim i As Int32
>For i = 0 To dstDataset.Tables(0).Rows.Count - 1
> 'Fill combobox with dataset content
> cbxAdmin.Items.Add(dstDataset.Tables(0).Rows.Item( i))
> Next
And Add:

Dim objDR as DataRow
For Each objDR in dstDataset.Tables(0).Rows
cbxAdmin.Items.Add(cstr(objdr("strName")))
Next

Good luck! Ken.



Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
10
by: localhost | last post by:
I have a static, thread-safe class with a DataSet as a property. When the class is instanced into an object, some callers add rows to a DataTable in the DataSet. Other callers read the DataSet. ...
12
by: Bishoy George | last post by:
I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties: ddLastName.DataSource =...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
7
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
3
by: BobAchgill | last post by:
I am trying to read in a xml file that I exported from my MSAccess table using the following lines of code but it bombs. Is this the right code? Is there a way to get a clean export from Access...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
by: OscarPiacenza | last post by:
Hello all. :) My name is Oscar and Im a novice on XML and dataset arguments. I need some help to resolve (and understand :) ) the following problem: I have stored some data in a SqlServer...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.