Visual Basic to SQL connection problem

Asked By 360 points N/A Posted on -
qa-featured

Hi everyone,

I am working on a Visual Basic project which is to be accessed by the end of the semester. I am supposed to connect to the SQL database, this is the final phase of the project but it is giving me a headache!

My connection code to the SQL database worked well yesterday, i woke up this morning and did a little bit of connection modification, which seemed right to me according to the tutorials i had. It is kind of i messed up because i can’t successfully connect to the SQL database.

The error in the SQL code line reads:

"Operator '&' is not defined for string "SELECT * FROM Clients WHERE Spec" and type 'DataRowView'."

I really don’t understand where i messed up because this is in its own sub. This specific buttons function is to check if an item selected in the check box exists in the database and then display the items.

Here is the code section,

Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
Dim strSQL As String
Dim dt As New DataTable
Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:Access2003Blank.mdb"

strSQL = "SELECT * FROM Clients WHERE Species = ' " & lstSpecies.SelectedItem & " ' " 'gets all clients that are of the right selected species type ERROR LINE

Dim dataAdapter As New _
OleDb.OleDbDataAdapter(strSQL, connStr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
DataGridDisplay.DataSource = dt

Can somebody help me out, Please?

SHARE
Best Answer by bert160488
Best Answer
Best Answer
Answered By 0 points N/A #106430

Visual Basic to SQL connection problem

qa-featured

Good Day,

Are you using MySQL or MS Access in Database? Well if you are using MySQL for database then you are connection is wrong. This Connection is for MS Access.

Dim connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=C:Access2003Blank.mdb"

If you are using MySQL you need to install first the driver ODB3.51 or higher.

As i can see in you are codes.

This Code:

strSQL = "SELECT * FROM Clients WHERE Species = ' " & lstSpecies.SelectedItem & " ' " 'gets all clients that are of the right selected species type ERROR LINE.

Try to remove single quote after in gets.

Like this> trSQL = "SELECT * FROM Clients WHERE Species = ' " & lstSpecies.SelectedItem & " ' " 

And try to check you tables in the database if it is right coz in MS Access or MySQL they key sensitive.

Hope this solve you are problem.

I'm waiting for you are feedback if you have already do the steps what i have given.

Thank you!

Login/Register to Answer

Related Questions