468,527 Members | 2,091 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,527 developers. It's quick & easy.

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 6555
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jeff Magouirk | last post: by
2 posts views Thread by ielmrani via SQLMonster.com | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.