-
Mar 14th, 2015, 03:55 PM
#1
Thread Starter
Addicted Member
Need help with from clause
Hello, I have an mdb database and I'm trying to check if some records exist, using a function. The code below is giving me syntax error in FROM clause.
Code:
Dim dbStr As String = "SELECT * FROM ? WHERE ? = ?"
Command = New OleDbCommand(dbStr, Connection)
Command.Parameters.AddWithValue("@table", t)
Command.Parameters.AddWithValue("@column", c)
Command.Parameters.AddWithValue("@value", v)
I want to learn if something is wrong with this code.
-
Mar 14th, 2015, 04:45 PM
#2
Re: Need help with from clause
It doesn't appear that you can use a table name as a parameter like any other. Here's a lengthy discussion that you might find useful:
http://www.sommarskog.se/dynamic_sql.html
My usual boring signature: Nothing
-
Mar 14th, 2015, 05:10 PM
#3
Re: Need help with from clause
You might want to learn SQL and ADO.NET before trying to use it
-
Mar 14th, 2015, 05:29 PM
#4
Thread Starter
Addicted Member
Re: Need help with from clause
-
Mar 14th, 2015, 10:59 PM
#5
Re: Need help with from clause
this would work though:
Code:
Dim dbStr As String = string.format("SELECT * FROM {0} WHERE {1} = ?", t, c)
Command = New OleDbCommand(dbStr, Connection)
Command.Parameters.AddWithValue("@value", v)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 15th, 2015, 09:18 AM
#6
Re: Need help with from clause
Not only would that work, it is probably the better answer.
My usual boring signature: Nothing
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|