What is wrong with this SQL statement - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HUKD, you accept our cookie and privacy policy.
Get the HUKD app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

What is wrong with this SQL statement

black gerbil1 Avatar
7y, 11m agoPosted 7 years, 11 months ago
the guys over at MSDN could not figure it out, im using the code in VB.net
black gerbil1 Avatar
7y, 11m agoPosted 7 years, 11 months ago
Options

All Comments

(17) Jump to unreadPost a comment
Comments/page:
#1
cmd.CommandText = cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"

is the code.



Private Sub cbmusiccategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbmusiccategory.SelectedIndexChanged
Dim cnn As OleDbConnection = New OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Hunter\Desktop\Student resources\CDs.mdb"
cnn.open()

Dim cmd As OleDbcommand = New OleDbcommand
cmd.CommandText = cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"
cmd.commandtype = CommandType.Text
cmd.connection = cnn



Dim da As OleDbDataAdapter = New OleDbDataAdapter
Dim dsartist As DataSet = New DataSet
da.SelectCommand = cmd
'the line below has the error of Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
da.Fill(dsartist, "ArtistsTable")



lbCds.DataSource = dsartist.Tables("ArtistsTable")


lbCds.DisplayMember = "Artist"

lbCds.ValueMember = "ArtistID"

cnn.close()
cnn.dispose()





End Sub

this is the sub that fails I get the error. "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'."

tried everywhere and and no-one knows.
2 Likes #2
Have you tried just running the statement via management studio? to make sure that this returns the results.
1 Like #3
If the code is as what you posted then...

cmd.CommandText = cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"

should really be...

cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"

without the extra @cmd.CommandText =@

Also, not sure about OLEDB (I use rdo mostly) but what does @cmd.commandtype = CommandType.Text@ do?
#4
tomblack258
Have you tried just running the statement via management studio? to make sure that this returns the results.


hi there tom, strong first post and welcome to HUKD.

I dont have management studio, but when i play the code and use the dropdown list from my combobox, it times out and i get the "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'." error message.

this leads me to believe the SQL is incorrect, ive checked for spelling mistakes and there are all spelt correctly.
#5
AyrshireBacon
If the code is as what you posted then...

cmd.CommandText = cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"

should really be...

cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"

without the extra @cmd.CommandText =@

Also, not sure about OLEDB (I use rdo mostly) but what does @cmd.commandtype = CommandType.Text@ do?

ha ha sick guy, it worked repped. I

thanks as well Tom.:thumbsup:

I have repped both and you have both gone up one bar. its the power i have on this site.
#6
surprising what you need to apply McDonalds
#7
black gerbil1
ha ha sick guy, it worked repped. I

thanks as well Tom.:thumbsup:

I have repped both and you have both gone up one bar. its the power i have on this site.


TYVM BG1.

The general rule about coding round here is that no-one can spot their own mistakes UNTIL you show someone else... :thumbsup:
#8
AyrshireBacon
TYVM BG1.

The general rule about coding round here is that no-one can spot their own mistakes UNTIL you show someone else... :thumbsup:

yeah I know, ive been looking at it for the past few hours and didn't know what was wrong, thought id let someone else look at it, i thought it would be a basic error which i just couldn't see.

:thumbsup:
jellybaby22
one bar...that all...wow...weak.......:)

lol what you got brah.
#9
i got 42k.
banned#10
black gerbil1
i got 42k.


Only another 34K to catch up with good members then.

Such weak rep.


BWAHAHAHAHA
#11
guv
Only another 34K to catch up with good members then.

Such weak rep.


BWAHAHAHAHA


:w00t::w00t:
banned#12
I have no rep, but I have a life
#13
black gerbil1;3905752

cmd.CommandText = cmd.CommandText = "SELECT tblArtists.ArtistID,tblArtists.Artist from tblArtists WHERE tblArtists.category= '" & cbmusiccategory.Text & "'"


Also switch over to using parameters for the condition - avoids injection nastiness.
#14
your database belong to er----------------
#15
alot of trolls on here today.
#16
I agree
#17
black gerbil1
alot of trolls on here today.


indeed, how are you:-D
tis the only way to increase your post count

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!