question using vb.net & mysql

Posted on 2012-09-14
Medium Priority
Last Modified: 2012-11-10
Below is code Im using to fill a datagridview. the problem with this is I have a class which contains all the db info and makes the connection
 instead of displaying it everytime here.
    Public Sub showCustomersDatagridView(ByVal query As String)

        Dim dbadp As New MySqlDataAdapter(query, "server=mydomain.com;" _
                                                        & "user id=vbnet;" _
                                                        & "password=password;" _
                                                        & "database=admin")
            Dim dTable As New DataTable


            DataGridView1.DataSource = dTable
            DataGridView1.Columns(0).Visible = False
            DataGridView1.Columns(1).Width = 220
            DataGridView1.Columns(1).HeaderText = "Company"
            DataGridView1.Columns(2).Width = 150
            DataGridView1.Columns(2).HeaderText = "Name"
            DataGridView1.Columns(3).Width = 125
            DataGridView1.Columns(3).HeaderText = "Telephone"

        Catch myerror As MySqlException
        End Try
    End Sub

Open in new window

This is the code I use to connect to the database that I would like to use
        Dim db As New databaseConnection()
        Dim cmd As New MySqlCommand
        cmd.CommandText = Query

        Dim dr As MySqlDataReader = db.DataReader(cmd)

Open in new window

Question by:prowebinteractiveinc
LVL 13

Expert Comment

by:Naman Goel
ID: 38401624
I can't understand your problem, what do you want with your class anyways you are having a DataTable that is serving your purpose.
LVL 40

Expert Comment

by:Vadim Rapp
ID: 38401808
LVL 35

Expert Comment

ID: 38401826
Can you post the code for your databaseConnection class?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 18

Expert Comment

ID: 38402075
Why are you using both a datareader and a dataadapter ?

Can you also be a little more specific in your question ? are you asking about encrypting your
connection information ?

Author Comment

ID: 38453269
I am abit new to vb.NET so maybe you can show me a better way

I would like to have one class to do the connection

I have connections to fill datagrid views, comboboxes, and textboxes
LVL 40

Accepted Solution

Vadim Rapp earned 2000 total points
ID: 38453340
The most straightforward is if you add new dataset file to the project, and there create datatable based on sql query. Then you will have the datatable with all the columns based on the query, and you won't need to create the columns in code. Then you can use GetData method of the dataadapter, and this will give you strong-typed dataset where each column will appear as a property.

If you have several data-based controls, all you need to do is specify the same connection for each one in its properties. To verify, open app.config of your project and see that you have there only one connection. If you see more, remove the rest and then fix any errors in the application that show up by specifying the remaining connection.

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question