473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Incorrect syntax near the keyword 'DEFAULT'

Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text); oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text); oleDbCommand_login.CommandText = "Select username from _users whereusername=? AND password=?"; // open the connection oleDbConnection_login.Open(); // execute the query oleDbCommand_login.Connection = oleDbConnection_login; object objResults = oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here // close the connection oleDbConnection_login.Close(); if (objResults==null) { return false; } return true;}
Nov 17 '05 #1
11 7074
Mark,

I would set in your place your command statement in a try block than you get
probably more information.

I had once this behaviour as well and than there was asked for 3 parameters.

I added a dummy one at the end and my problem was gone.
Until now I don't know the reason for this behaviour.

Cor
Nov 17 '05 #2
Thanks for Cor's inputs.

Hi Mark, if it's the sql statement that cause the error, I'll suggest you
turn on the sql profiler at the sqlserver side to monitor the actually
executed sqlstatement. And you can compare it with the correct one (which
you can get executed correctly in SQL Query Analyzer).

Hope also helps. If still anything unclear or need any further assistance,
please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Cor Ligthert [MVP]" <no************@planet.nl>
| References: <eU**************@TK2MSFTNGP15.phx.gbl>
| Subject: Re: Incorrect syntax near the keyword 'DEFAULT'
| Date: Mon, 1 Aug 2005 06:58:11 +0200
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <ut**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.adonet,microsoft .public.dotnet.languages.c
sharp
| NNTP-Posting-Host: ip3e830773.speed.planet.nl 62.131.7.115
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.languages.csharp:113390
microsoft.public.dotnet.framework.adonet:33238
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Mark,
|
| I would set in your place your command statement in a try block than you
get
| probably more information.
|
| I had once this behaviour as well and than there was asked for 3
parameters.
|
| I added a dummy one at the end and my problem was gone.
| Until now I don't know the reason for this behaviour.
|
| Cor
|
|
|

Nov 17 '05 #3
Hi,

Where is "DEFAULT" ? I see it nowhere in your code

Are you using a trigger?

what if you run this in the SQL query analyser?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mark Findlay" <mf******@speakeasy.org> wrote in message
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text);
oleDbCommand_login.CommandText = "Select username from _users
whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}

Nov 17 '05 #4
On Sun, 31 Jul 2005 19:51:04 -0700, "Mark Findlay" <mf******@speakeasy.org> wrote:

¤ Hello Experts!
¤
¤ I am attempting to use the OleDbCommand.ExecuteScaler() function within my
¤ ASP.NET C# web page to perform a simple validation, but receive the
¤ following error:
¤
¤ "Incorrect syntax near the keyword 'DEFAULT'"
¤
¤ The form has 2 fields on it, called tb_username and tb_password. (see code
¤ snippet below).
¤ The SQL Server table is called _users and has a number of columns, 2 of
¤ which I am reading: username and password.
¤
¤ I've searched the net for any clues on this but so far none of the items
¤ I've found were relavent to what I was doing. Can anyone shed any light on
¤ this?
¤
¤ Many thanks!
¤
¤ === here is my code ====
¤
¤ private bool ValidateLogin()
¤ {
¤ // set the connection string
¤ oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;
¤
¤ // add parameters to the query
¤ oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text); oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text); oleDbCommand_login.CommandText = "Select username from _users whereusername=? AND password=?"; // open the connection oleDbConnection_login.Open(); // execute the query oleDbCommand_login.Connection = oleDbConnection_login; object objResults = oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here // close the connection oleDbConnection_login.Close(); if (objResults==null) { return false; } return true;}

Unless that's a typo in your post, a blank space is omitted between the WHERE keyword and username
column name. I don't see the keyword DEFAULT in that statement.
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 17 '05 #5

username and password need single quotes around values, something like this:

oleDbCommand_login.CommandText = "Select username from _users where
username='myusername' AND password='mypwd'"; // open the connection

"Mark Findlay" wrote:
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text); oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text); oleDbCommand_login.CommandText = "Select username from _users whereusername=? AND password=?"; // open the connection oleDbConnection_login.Open(); // execute the query oleDbCommand_login.Connection = oleDbConnection_login; object objResults = oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here // close the connection oleDbConnection_login.Close(); if (objResults==null) { return false; } return true;}

Nov 17 '05 #6
AFAIK it uses the default keyword when it finds no mapping. Usually I set
the parameters after the commandtext. Are you sure it doesn't reset the
collection ?

Patrice

--

"Mark Findlay" <mf******@speakeasy.org> a écrit dans le message de
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query

oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWCh
ar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWCh
ar,25,tb_password.Text); oleDbCommand_login.CommandText = "Select username
from _users whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}
Nov 17 '05 #7
The "DEFAULT" is not part of my code, it is only contained in the error
message.

Thanks,
Mark

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:O2*************@TK2MSFTNGP09.phx.gbl...
Hi,

Where is "DEFAULT" ? I see it nowhere in your code

Are you using a trigger?

what if you run this in the SQL query analyser?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mark Findlay" <mf******@speakeasy.org> wrote in message
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within
my ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see
code snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light
on this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text);
oleDbCommand_login.CommandText = "Select username from _users
whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults
= oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}



Nov 17 '05 #8
Sorry Paul, that's just a typo in my message. There is in fact a space
between WHERE and the where clause.

Thanks,
Mark

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:lm********************************@4ax.com...
On Sun, 31 Jul 2005 19:51:04 -0700, "Mark Findlay"
<mf******@speakeasy.org> wrote:

¤ Hello Experts!
¤
¤ I am attempting to use the OleDbCommand.ExecuteScaler() function within
my
¤ ASP.NET C# web page to perform a simple validation, but receive the
¤ following error:
¤
¤ "Incorrect syntax near the keyword 'DEFAULT'"
¤
¤ The form has 2 fields on it, called tb_username and tb_password. (see
code
¤ snippet below).
¤ The SQL Server table is called _users and has a number of columns, 2 of
¤ which I am reading: username and password.
¤
¤ I've searched the net for any clues on this but so far none of the items
¤ I've found were relavent to what I was doing. Can anyone shed any light
on
¤ this?
¤
¤ Many thanks!
¤
¤ === here is my code ====
¤
¤ private bool ValidateLogin()
¤ {
¤ // set the connection string
¤ oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;
¤
¤ // add parameters to the query
¤
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text);
oleDbCommand_login.CommandText = "Select username from _users
whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}

Unless that's a typo in your post, a blank space is omitted between the
WHERE keyword and username
column name. I don't see the keyword DEFAULT in that statement.
Paul
~~~~
Microsoft MVP (Visual Basic)


Nov 17 '05 #9
I tried moving the parameters after the commandtext and still receive the
same error.

Thanks,
Mark

"Patrice" <no****@nowhere.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
AFAIK it uses the default keyword when it finds no mapping. Usually I set
the parameters after the commandtext. Are you sure it doesn't reset the
collection ?

Patrice

--

"Mark Findlay" <mf******@speakeasy.org> a écrit dans le message de
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within
my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see
code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light
on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query

oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWCh
ar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWCh
ar,25,tb_password.Text); oleDbCommand_login.CommandText = "Select username
from _users whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}


Nov 17 '05 #10
Try using the parameter names in your command, e.g. "where username =
@user AND password = @pass", rather than the placeholders, "where
username = ? AND password = ?". I have found that using the question
mark placeholders works for me with ODBC, not OLEDB, and that named
parameters have worked for me with OLEDB, but not ODBC.

Hope this is helpful...

zdrakec

Nov 17 '05 #11
I believe I found the solution:

For a select query, I am not allowed to use the format of the
Parameters.Add() function I am currently using:
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text);

Instead, when I used the following format, it all worked fine:
oleDbCommand_login.Parameters.Add("@user",tb_usern ame.Text);

I believe the explanation lies in the help screen for the Parameters.Add()
function from the Dynamic Help in Visual Studio.NET. It states:
"Adds an OleDbParameter to the OleDbParameterCollection given the
parameter name, data type, column length, and source column name."

Notice the end of the text: "source column name". In my usage, I am not
providing the source column name, I am providing the textbox from my webpage
where the parm value is to be read. I'm definitely no expert on VS.NET etc.,
but it would appear from the dynamic help text above that using this form of
Parameters.Add() is not appropriate for a select statement. Odd though,
since I pulled my usage out of a textbook.

Thanks for everyone's input. I hope this answer helps anyone else looking
in.

Mark

"Mark Findlay" <mf******@speakeasy.org> wrote in message
news:eU**************@TK2MSFTNGP15.phx.gbl...
Hello Experts!

I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:

"Incorrect syntax near the keyword 'DEFAULT'"

The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
The SQL Server table is called _users and has a number of columns, 2 of
which I am reading: username and password.

I've searched the net for any clues on this but so far none of the items
I've found were relavent to what I was doing. Can anyone shed any light on
this?

Many thanks!

=== here is my code ====

private bool ValidateLogin()
{
// set the connection string
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

// add parameters to the query
oleDbCommand_login.Parameters.Add("@user",System.D ata.OleDb.OleDbType.VarWChar,25,tb_username.Text);
oleDbCommand_login.Parameters.Add("@pass",System.D ata.OleDb.OleDbType.VarWChar,25,tb_password.Text);
oleDbCommand_login.CommandText = "Select username from _users
whereusername=? AND password=?"; // open the connection
oleDbConnection_login.Open(); // execute the query
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); <--- errormessage occurs here //
close the connection oleDbConnection_login.Close(); if (objResults==null)
{ return false; } return true;}


Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3)...
2
by: JMUApache | last post by:
Hi, I have got a error message while I run a sample OLEDB program. It says "Incorrect Syntax Near The Keyword Default Information". platform: Windows XP + Visual Studio 2005 Beta 2 + SQL...
2
by: Jon | last post by:
hi, i was trying to create a DB in a SQL Server. but when i try to connect it with : Dim conn As SqlConnection = New SqlConnection("Initial Catalog=master; " & _ "Data Source=SERVER-MACHINE;" &...
2
by: ielmrani via SQLMonster.com | last post by:
Hi Everyone, I really tried to not post this question but I gave up. I tried brackets, parenth...etc but nothing worked. I get this error message: Incorrect syntax near the keyword 'THEN'. ...
0
by: netone | last post by:
I am developing site using dot NET.... when I use this sql query Dim mydata As String = "SELECT director.applno, district.distName, disabappl.recvddate_sdo, disabappissue.IDCardNo,...
3
by: wallic | last post by:
Hello, This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). ...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
1
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
5
by: beenanair11 | last post by:
Hi friends, Im getting an error,in a particular line System.Data.OleDb.OleDbException: Incorrect syntax near the keyword 'DEFAULT'. at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.