SQL query returning Too Few Parameters [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have an access database that I am attempting to reference a SQL query
Set dba = CurrentDb
SQL = "SELECT * FROM tbl_NewHireStep WHERE Location = '" & Site & "' AND E-Verified = TRUE "
Set rst = dba.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
Keeps giving me a Too few parameters error. In SQL it works great. What am I doing wrong?

The hyphen, -, is an Access reserved symbol. If you want to use it in a field or table name, then you must always put that field or table name inside square brackets when you reference it. For example,
SQL = " SELECT * FROM tbl_NewHireStep " & _
" WHERE Location = '" & Site & "' AND [E-Verified] = TRUE "
It's far better to avoid using reserved words and symbols in the first place. Several years ago, Allen Browne compiled a list of Problem names and reserved words in Access. I'm not sure how current the list is, but it is a great reference when creating new database schemas.

Related

SQL Insert Query With Condition Exception [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have this query:
String requete = "INSERT INTO reduction(newPrix) VALUES (?) "
+ "WHERE id_prom=? AND id_prod=?";
I am getting an exception:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'WHERE id_prom=2 AND id_prod=6' at line 1
I'm wondering why the INSERT query was failing. Any advise appreciated.
You insert a row into your table.
This means that you need to specify all mandatory values (i.e. values for the columns that are not nullable and don't have a default value).
You can't use a where clause in this kind of insert statement. What would it mean? And in your program you can verify the validity of the data you'd like to add to your table and decide to insert or not.

Syntax error (missing operator) in query expression ‘[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]’ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have to create a list box control that contains all of the queries except for the system queries. Recall that system query names begin with the ~ character.
When I try to write SQL code in the row source (in the property sheet) for my frmQueries form I keep getting an error saying:
Syntax error (missing operator) in query expression:'[Type]=5 And Left([Name],1)<>"~" OORDER BY [Name]'
The code I entered is:
SELECT [Name] FROM MYSysObjects
WHERE [Type]=5 And Left([Name],1)<>"~"
OORDER BY [Name];
I am not sure why I am getting this error or how I can fix it.
OORDER should be ORDER, MYSysObjects should (presumably) be MSysObjects, and you can also replace Left([Name],1)<>"~" with [Name] not like "~*" (assuming MS Access instead of SQL Server).

Fetching VB Variables to insert with SQL Query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Hello everybody hope you are well.
I have a place on a project im working on that im struggling to get past. I'm basically gathering meta data of a song and assigning them to variables in VB.
I'm next trying to save this data to a SQL database with tables i have created in visual studio and im having trouble doing this. The problem lies within trying to link the VB variables into a SQL query. Any Ideas?
To link VB variables to an SQL query, you need to add parameters that store the variables and then use those parameters in your SQL command:
Using parameters
MyCommand = New SqlCommand("SELECT Height, Weight, DoB, Gender, FROM `User` WHERE Username = #Username", DatabaseConnection)
MyCommand.Parameters.AddWithValue("#Username", Username)
UPDATE: How to connect to database
'Leads to the database
Public Filename As String = $"{AppDomain.CurrentDomain.BaseDirectory}YourDatabase.accdb"
'The connection string is set
Public ConStr As String = $"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA Source = {Filename}"
'The connection to the database is defined
Public DatabaseConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConStr)

Why some rows can be inserted into and some cannot? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I use the Cashier table or some other tables that have small amounts of records the process proceeds and table is inserted into the external database. But when I change the cashier into the transaction database (400k+ records), Visual Studio reports an error near "Transaction" Help would be appreciated thanks.
Cashier Database (working)
Dim query As String = "select * into MyDatabase2.dbo.Cashier from bos_primary_db.dbo.Cashier"
Transaction Database (not working)
Dim query As String = "select * into MyDatabase2.dbo.Transaction from bos_primary_db.dbo.Transaction"
This is the error message:
Incorrect syntax near the keyword 'Transaction'
this is probably because Transaction is a reserved word in SQL.
Depending on your RDBMS (that you didn't specify), there are ways to "escape" it:
for Sql Server, you should wrap reserved words in square brackets:
select * into MyDatabase2.dbo.[Transaction] from bos_primary_db.dbo.[Transaction]
For MySql you should use an apostrophe:
select * into MyDatabase2.dbo.`Transaction` from bos_primary_db.dbo.`Transaction`
For Oracle you should use double quotes:
select * into MyDatabase2.dbo."Transaction" from bos_primary_db.dbo."Transaction"
Note: You should always try to avoid using reserved words. This link describes my favorite way of do it.

Syntax not valid on word 'ON' in SQL join statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to run an SQL SELECT statement which is running correctly in SQL Server Management Studio, but I keep receiving the error while trying to run the below code in Visual Basic/Studio:
In correct syntax near the word 'ON'
Code:
com = New SqlCommand("SELECT Member_Details.mMember_ID AS 'Unique ID', Member_Details.mFirst_Name + Member_Details.mLast_Name AS 'Name', CONVERT(varchar(10),Member_Details.mDoB,103) AS 'Date of Birth', Member_Details.mGender AS 'Gender', Rep_Group.rRep_Group_Name AS 'Rep Group'" & _
"FROM Member_Details" & _
"Join(Rep_Group) ON Member_Details.mRep_Group=Rep_Group.rRep_Group_ID", con)
The error message:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'ON'.
The SQL Statement does work without the Join statement, so I think I'm just formatting it wrong in Visual Studio.
Replace Join(Rep_Group) with Join Rep_Group in your code. JOIN is not a function :)