question using & mysql

Posted on 2012-09-14
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, ";" _
                                                        & "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
    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
    LVL 33

    Expert Comment

    Can you post the code for your databaseConnection class?
    LVL 18

    Expert Comment

    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

    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

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now