关键字'DEFAULT'附近的语法不正确 [英] Incorrect syntax near the keyword 'DEFAULT'

查看:211
本文介绍了关键字'DEFAULT'附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家!


我试图在我的

ASP.NET C#网页中使用OleDbCommand.ExecuteScaler()函数来执行一个简单的操作验证,但收到

以下错误:


"关键字''DEFAULT'附近的语法错误"


表单上有2个字段,名为tb_username和tb_password。 (参见下面的代码

片段。)

SQL Server表名为_users,有多列,2个

我是阅读:用户名和密码。


我在网上搜索了这方面的任何线索,但到目前为止没有任何项目

我找到了与我正在做的事情相关。这个人可以点亮这个吗?


非常感谢!


===这是我的代码====


private bool ValidateLogin()

{

//设置连接字符串

oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;


//为查询添加参数

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 ="从_users中选择用户名whereusername =? AND password =?" ;; //打开连接oleDbConnection_login.Open(); //执行查询oleDbCommand_login.Connection = oleDbConnection_login; object objResults = oleDbCommand_login.ExecuteScalar(); < --- errormessage发生在这里//关闭连接oleDbConnection_login.Close(); if(objResults == null){return false; } return true;}

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;}

推荐答案

标记,


我会在你的位置设置你的命令声明一个试试块比你得到

可能更多的信息。


我曾经有过这种行为,并且要求3个参数。


我最后添加了一个假的,我的问题就消失了。

到现在为止,我不知道这种行为的原因。

Cor
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


感谢Cor的输入。


马克,如果是的话导致错误的sql语句,我建议你打开sqlserver端的sql profiler来监视实际上执行sqlstatement的
。你可以将它与正确的一个进行比较(你可以在SQL查询分析器中正确执行
)。


希望也有帮助。如果还有什么不清楚或需要任何进一步的帮助,

请随时在这里发布。


谢谢,


Steven Cheng

Microsoft在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

---------------- ----

|来自:Cor Ligthert [MVP] < no ************ @ planet.nl>

|参考文献:< eU ************** @ TK2MSFTNGP15.phx.gbl>

|主题:Re:关键字''DEFAULT'附近的语法不正确

|日期:星期一,2005年8月1日06:58:11 +0200

|行数:13

| X-Priority:3

| X-MSMail-Priority:正常

| X-Newsreader:Microsoft Outlook Express 6.00.2900.2670

| X-MIMEOLE:由Microsoft MimeOLE制作V6.00.2900.2670

| X-RFC2646:格式=流动;回复

|消息ID:< ut ************** @ TK2MSFTNGP10.phx.gbl>

|新闻组:

microsoft.public.dotnet.framework.adonet,microsoft .public.dotnet.languages.c

sharp

| NNTP-Posting-Host:ip3e830773.speed.planet.nl 62.131.7.115

|路径:TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl

|外翻:TK2MSFTNGXA01.phx.gbl

microsoft.public.dotnet.languages.csharp:113390

microsoft.public.dotnet.framework.adonet:33238

| X-Tomcat-NG:microsoft.public.dotnet.languages.csharp

|

|马克,

|

|我会在你的位置设置你的命令语句,而不是你想要的块。

get

|可能更多信息。

|

|我曾经有过这种行为,而且还要求3

参数。

|

|我在最后添加了一个假的,我的问题就消失了。

|到现在为止,我不知道这种行为的原因。
|

| Cor

|

|

|

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
|
|
|





哪里是DEFAULT ?我在你的代码中看不到它


您是否正在使用触发器?


如果您在SQL查询分析器中运行它会怎么样? />

欢呼,

-

Ignacio Machin,

ignacio.machin AT dot .state.fl.us

佛罗里达州交通局


" Mark Findlay" < MF ****** @ speakeasy.org>在消息中写道

新闻:eU ************** @ TK2MSFTNGP15.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 Expert!

我试图在我的ASP.NET C#网页中使用OleDbCommand.ExecuteScaler()函数来执行简单的验证,但收到以下错误:

"关键字''DEFAULT'附近的语法不正确'"

表单上有2个字段,名为tb_username和tb_password。 (请参阅下面的代码
代码段。)
SQL Server表名为_users,有许多列,我正在阅读的是
:用户名和密码。

非常感谢!

===这里是我的代码====

private bool ValidateLogin()
//
//设置连接字符串
oleDbConnection_login.ConnectionString = C_Constants.g_sDSN;

//为查询添加参数 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 ="从_users中选择用户名
whereusername =? AND password =?" ;; //打开连接
oleDbConnection_login.Open(); //执行查询
oleDbCommand_login.Connection = oleDbConnection_login; object objResults =
oleDbCommand_login.ExecuteScalar(); < --- errormessage发生在这里//
关闭连接oleDbConnection_login.Close(); if(objResults == null)
{return false; } return true;}
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;}



这篇关于关键字'DEFAULT'附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆