adding items to list box control from a dataset

Larry Rungren
Larry Rungren used Ask the Experts™
on
in this code the lstall.items.add  generate error

Argument not specified for parameter item??  


          If txtGroup.Text <> "" Then
                lstAllSem.Items.Clear()
                lstSelSem.Items.Clear()
                txtGroup.Text = Replace(txtGroup.Text, "'", "''")
                lstallAdp = New SqlDataAdapter("select * from meet_master where muf_8 = '" & txtGroup.Text & "'", sqlCnn)
                Try
                    lstallAdp.Fill(da)
                Catch ex As Exception
                End Try
                If da.Tables(0).Rows.Count = 0 Then
                    '            MsgBox("No program group available. Selection of other Seminars  not possible.. Continue?", vbYesNo)
                Else
                    Dim dta As DataTable
                    Dim dro As DataRow
                    dta = da.Tables(0)

                    For Each dr0 In dta.Rows

                        lstAllSem.Items.Add = da.Tables(0).Rows(0)("meeting").ToString()
                    Next dr0

                    dta.Dispose()

                End If

            End If

Open in new window



Any help greatly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
da.Tables(0).Rows(0).Item("meeting").ToString()
Top Expert 2016

Commented:
Hi,

pls try

 lstAllSem.Items.Add = dr0.Item("meeting").ToString()

Open in new window


Regards
Fernando SotoRetired
Distinguished Expert 2017

Commented:
I think this is what you are looking for.
lstAllSem.Items.Add = dr0("meeting").ToString()

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Larry RungrenDirector of Technology

Author

Commented:
Thanks for the speedy responses but all three options generate the same error!!
Larry RungrenDirector of Technology

Author

Commented:
Dot net certainly has been a major step backwards in the development cycle.  I have found so many things that were done in 3 or 4 lines of code now require 40 -50 lines with all sorts of hidden methods and layered access techniques.  Kinda like going back to proprietary OS's that had massive function libraries that took months if not years to truly master.  Typical MSFT move forward, but cut off the past completely, and the time and expense for the move is ours to swallow, Just my opinion.
Top Expert 2015
Commented:
You have it in reverse. Most of the time, .NET enables you to do things with far fewer lines of code. When you end up using more code to do something in .NET that you did in VB6, it's because you do not use .NET correctly.

In your code for instance, you declare a variable dta, initialize it and Dispose of it, but never use it because you go through the DataSet to reference your table.

You declare a DataRow but never use it.

You are using a DataSet when you have only one table. DataSet are used when you have many DataTable objects linked together with DataRelation objects. See my article on the subject.

You call a query that retrieves all the fields from your database table, but you use only one of these fields. The following would be sufficient to fill the ListBox:

... 
lstallAdp = New SqlDataAdapter("select meeting from meet_master where muf_8 = '" & txtGroup.Text & "'", sqlCnn)
lstallAdp.Fill(da)
...
lstAllSem.DataSource=da.Tables(0)
lstAllSem.DisplayMember="meeting"

Open in new window


And usually a DataReader is a lot better choice than a DataAdapter when you need to fill a ListBox or a ComboBox and need only one field. Once again, give a look at my article.
Larry RungrenDirector of Technology

Author

Commented:
Jacques Bourgeois (James Burger)

Sorry if I seem negative.. First major conversion and what was second nature,  16 years VB4-6, is seemingly a different universe with no real easy path upward.  Documentation is sketchy at best and most  sample processes I can find seem to relate to gridview options.  A true desktop, data entry process sample seems to be lacking.  I've made great headway, and the only hangup is connecting existing Crystal Reports 2011 report to vb2010 without rewriting them.  I have 14 reports in this app that ran fine under VB6, but that is for another day.
Larry RungrenDirector of Technology

Author

Commented:
Thanks for the help and the smack back to reality.
Top Expert 2015

Commented:
I understand your frustrations. I went through them too at the beginning of the century, having used VB from VB2 to VB6, and training other programmers from VB3 to VB6.

But keep with it. VB.NET is a far better environment and language than VB6 was. There might be a few things that take a few lines of code more than before. But they are a small fee for what usually ends up as more performance and security (although security is often frustating in .NET). And expect to write a lot less code. In the 10,000+ classes of the framework, there is almost always a method somewhere that will do what you want to do. You just need to take the time to look for it.

It took me 60 lines of codes in VB6 to retrieve the format of the date, as set in the Control Panel, in a bilingual environment. Around 20 for the number format. It takes only 1 line for each once you have discovered the System.Globalization namespace. Try to get the date a file was created or last opened without being written to in VB6. A one line thing again in .NET.

You might find that working with database involves a little more, and it does, but not much once you get your ways with the System.Data namespace. Up to 2 years ago, I was still stuck with unfrequent maintenance with old VBA code in Microsoft Access, and I missed ADO.NET almost everytime I had to go back to Recordsets. Start doing web or mobile development, and you will understand and appreciate even more the new ways of doing database stuff, and that you do not have to learn new techniques. ADO.NET is the same way no matter the type of application.

Get used to the documentation too. It is a lot better than it was in VB6. It's just that it is so huge that it takes a while before you grab the proper ways to use it. Install the local help that is not installed by default and use it as your first source instead of online help. Local help can be adapted to what you do. If you do not do Web development, do not install the web modules and they won't show up when you search. And the local help has an Index, something that is really lacking with online help, where the only way to go is through search. When you need to search outside of the tools that Visual Studio link you with, use Bing instead of Google. Bing being a Microsoft thing, they have a tendency to emphasize their own products. I find that you usually find information about Microsoft tools and apllications more easily on Bing than when you go through Google, that makes its money by throwing in stuff for companies that paid to get moved up the result of a search.

As for Crystal Report, well... it's Crystal Report. Don't blame .NET. Blame the 101 companies who worked on Crystal Report since it's inception, and who have never completely nailed it. And still don't, even if .NET has been officially around for more than 13 years.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial