首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

急sql语句出现有关问题!

2012-01-16 
急,sql语句出现问题!!%@PageLanguage C# %%@ImportNamespace System.Data %%@ImportNamespace

急,sql语句出现问题!!
<%@   Page   Language= "C# "   %>
<%@   Import   Namespace= "System.Data "   %>
<%@   Import   Namespace= "System.Data.OleDb "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<script   runat= "server ">

        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                string   dbname;
                dbname   =   Server.MapPath( "system.mdb ");

                OleDbConnection   conn   =   new   OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA   Source= "   +   dbname);
                conn.Open();

                string   yonghu,   mima,sqlconn;
                yonghu   =   TextBox1.Text;
                mima   =   TextBox2.Text;
                sqlconn   =   "select   user,name   from   jhtuser   where   user   =   " "+   yonghu+ " "   and   pass   =   " "+mima+ " " ";
                OleDbCommand   cmd   =   new   OleDbCommand(sqlconn,   conn);


                OleDbDataReader   dr   =   cmd.ExecuteReader();
                if   (dr.Read())


                        Response.Redirect( "helps.htm ");  
                else

                        Response.Redirect( "index.asp ");  
        }

       
</script>

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> 无标题页 </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                <asp:Label   ID= "Label1 "   runat= "server "   Text= "用户名: "> </asp:Label>
                <asp:TextBox   ID= "TextBox1 "   runat= "server "   ValidationGroup= "TextBox1 "> </asp:TextBox>
                <asp:RequiredFieldValidator   ID= "RequiredFieldValidator1 "   runat= "server "   ErrorMessage= "请输入用户名! "   ControlToValidate= "TextBox1 "   > 请输入用户名! </asp:RequiredFieldValidator> <br   />
                <br   />


                <asp:Label   ID= "Label2 "   runat= "server "   Text= "密码: "> </asp:Label>
                <asp:TextBox   ID= "TextBox2 "   runat= "server "> </asp:TextBox>
                <asp:RequiredFieldValidator   ID= "RequiredFieldValidator2 "   runat= "server "   ControlToValidate= "TextBox2 "
                        ErrorMessage= "请输入密码! "> </asp:RequiredFieldValidator> <br   />
                <br   />
                <asp:Button   ID= "Button1 "   runat= "server "   OnClick= "Button1_Click "   Text= "登陆 "   />
                <asp:Button   ID= "Button2 "   runat= "server "   Text= "取消 "   />
                </div>
        </form>
</body>
</html>

这行出错:   sqlconn   =   "select   user,name   from   jhtuser   where   user   =   " "+   yonghu+ " "   and   pass   =   " "+mima+ " " ";

出错信息:
C:\Program   Files\Microsoft   Visual   Studio   8\Common7\IDE>   "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe "   /t:library   /utf8output   /R: "C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll "   /R: "C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll "   /R: "C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll "   /R: "C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll "   /R: "C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll "   /R: "C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll "   /R: "C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll "   /R: "C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll "   /R: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll "   /R: "C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll "   /out: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary   ASP.NET   Files\website1\d61112bf\fb265f28\App_Web_qgkqivbf.dll "   /D:DEBUG   /debug+   /optimize-   /w:4   /nowarn:1659;1699     "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary   ASP.NET   Files\website1\d61112bf\fb265f28\App_Web_qgkqivbf.0.cs "   "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary   ASP.NET   Files\website1\d61112bf\fb265f28\App_Web_qgkqivbf.1.cs "   "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary   ASP.NET   Files\website1\d61112bf\fb265f28\App_Web_qgkqivbf.2.cs "


Microsoft   (R)   Visual   C#   2005   编译器   版本   8.00.50727.42
用于   Microsoft   (R)   Windows   (R)   2005   Framework   版本   2.0.50727


版权所有   (C)   Microsoft   Corporation   2001-2005。保留所有权利。

c:\Documents   and   Settings\X\My   Documents\Visual   Studio   2005\WebSites\WebSite1\login.aspx(20,64):   error   CS1002:   应输入   ;
c:\Documents   and   Settings\X\My   Documents\Visual   Studio   2005\WebSites\WebSite1\login.aspx(20,75):   error   CS1002:   应输入   ;
c:\Documents   and   Settings\X\My   Documents\Visual   Studio   2005\WebSites\WebSite1\login.aspx(20,89):   error   CS1002:   应输入   ;
c:\Documents   and   Settings\X\My   Documents\Visual   Studio   2005\WebSites\WebSite1\login.aspx(20,97):   error   CS1002:   应输入   ;


[解决办法]
sqlconn = "select user,name from jhtuser where user = ' "+ yonghu+ " ' and pass = ' "+mima+ " ' ";

[解决办法]
sqlconn = "select user,name from jhtuser where user = ' "+ yonghu+ " ' and pass = ' "+mima+ " ' ";


不可用“”号 ( ' "+ yonghu+ " ')( ' "+mima+ " ' ")
[解决办法]

将字段值的双引,改成单引号
[解决办法]
string mySel= "SELECT count(*) as iCount from user where UserID= " "+userid+ " " ";

如果UserID字段是整数的话,可以这么写 where UserID= "+userid+ " ";
如果是字符型要这么写 where UserID= ' "+userid+ " ' ";

你的是错的哦 仔细对照下

热点排行