473,780 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OleDbDataAdapte r(strSQLSelect, dbConnector)
Cmd.Fill(dstDat aset)

Return dstDataset
End Function

Private Sub fillComboBoxAdm in()
Dim dstDataset As DataSet
dstDataset = mySQL()
Dim i As Int32
For i = 0 To dstDataset.Tabl es(0).Rows.Coun t - 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
fillComboBoxAdm in, I can't get anything out of the dataset.

Thanks
Marty







Jul 21 '05 #1
7 1807
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.Mess age)
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.Tabl es(0).Rows.Coun t - 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.Tabl es(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.foru m> wrote in message
news:P1******** *******@fe51.us enetserver.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 OleDbDataAdapte r(strSQLSelect, dbConnector)
Cmd.Fill(dstDat aset)

Return dstDataset
End Function

Private Sub fillComboBoxAdm in()
Dim dstDataset As DataSet
dstDataset = mySQL()
Dim i As Int32
For i = 0 To dstDataset.Tabl es(0).Rows.Coun t - 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
fillComboBoxAdm in, 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.Mess age)
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.Tabl es(0).Rows.Coun t - 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.Tabl es(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.foru m> wrote in message
news:_G******** ********@fe51.u senetserver.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.Mess age)
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.Tabl es(0).Rows.Coun t - 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.Tabl es(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 fillComboBoxAdm in()
cbxAdmin.dataso urce = mySQL()
cbxAdmin.displa ymember = "TheColumNa me"
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.foru m> wrote in message
news:_G******** ********@fe51.u senetserver.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
...databas e code
Catch exc as Exception
msgbox(exc.Mess age)
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.Tabl es(0).Rows.Coun t - 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.Tabl es(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.Da taViewManagerLi stItemTypeDescr iptor"

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 fillComboBoxAdm in()
cbxAdmin.dataso urce = mySQL()
cbxAdmin.displa ymember = "TheColumNa me"
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 OleDbDataAdapte r 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:

<OleDbDataAdapt ername>.Fill(<D ataSetname>.Tab les("<DataTable name>"))

In the <comboboxname>_ SelectedValueCh anged 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.Select edValue

' 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.foru m> wrote in message
news:zN******** ********@fe51.u senetserver.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.foru m> wrote in message
news:_G******** ********@fe51.u senetserver.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
...databas e code
Catch exc as Exception
msgbox(exc.Mess age)
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.Tabl es(0).Rows.Coun t - 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.Tabl es(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
6169
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 then appends the data to a dataset that is built in the Page_Load code in the if(!isPostBack) block. When I try to add a row in the button click event code I get an error saying that "Object reference not set to an instance of an object". I'm...
10
1533
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. When any caller reads the DataSet, I want the object to delete all of the rows in the DataTable. I think I want to make a custom event but I don't know where/how to get started. Help? Thanks.
12
1693
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 = ds1; ddLastName.DataMember = "Employees"; ddLastName.DataTextField = "LastName"; ddLastName.DataBind(); ddLastName.Items.Insert(0,"Select:");
16
2489
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 it with incremental values e.g. if the tables looks like this: 23 56
7
1123
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 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
3
4632
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 so the XML file will read in OK into a VB .Net Form dataset? =============================== Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
22
25604
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 compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet = ws.VerifySku(cartSet)
1
9654
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
0
1670
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 database. I read data stored in database using a DbDataAdapter which fill a dataset. One of the columns DataType of the dataset is a System.Byte containing an array of bytes. (In the SqlServer database it is stored as VarBinary field). For...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.