• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

question using vb.net & mysql

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")
        Try
            Dim dTable As New DataTable

            dbadp.Fill(dTable)

            dbadp.Dispose()
            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
            MessageBox.Show(myerror.Message)
        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()
        db.OpenConnection()
        Dim cmd As New MySqlCommand
        cmd.CommandText = Query

        Dim dr As MySqlDataReader = db.DataReader(cmd)

Open in new window

0
prowebinteractiveinc
Asked:
prowebinteractiveinc
1 Solution
 
Naman GoelSoftware engineer 1Commented:
I can't understand your problem, what do you want with your class anyways you are having a DataTable that is serving your purpose.
0
 
Vadim RappCommented:
0
 
NorieVBA ExpertCommented:
Can you post the code for your databaseConnection class?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
vbturboCommented:
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 ?
0
 
prowebinteractiveincAuthor Commented:
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
0
 
Vadim RappCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now