473,382 Members | 1,720 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,382 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







Nov 21 '05 #1
7 1112
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






Nov 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.

Nov 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.


Nov 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
Nov 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.



Nov 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

Nov 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.



Nov 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...
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...
4
by: geilen | last post by:
I'm trying to use a dataset returned from a web service in an unmanaged C++ (MFC) client. The dataset is returned as a BSTR, and I'm having trouble reading the BSTR into an XML document for...
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...
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 I’m 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.