Asp按钮没有触发 [英] Asp button is not firing

查看:68
本文介绍了Asp按钮没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



i在一个管理文件夹里面有一个adminlogin页面,不在根目录中



in adminlogin.aspx页面有登录表单(NOT LOGIN TOOLBOX)有一个名为Signin的按钮如果我点击登录按钮就会出现错误:



错误:语法附近不正确'', ''。



即使没有触发按钮

请求帮助我

我应该在管理员内部需要两个webconfig文件文件夹?





我的登录按钮代码

瘦LoginButton在admin文件夹中不在根目录下的页面是login.aspx

hi friends

i have a adminlogin page inside a admin folder not in root directory

in adminlogin.aspx page there is login form ( NOT LOGIN TOOLBOX) there a button called Signin if i click the signin button am getting a error:

ERROR : Incorrect Syntax near'',''.

the even is not firing in button
pleas help me
should i need two webconfig file inside admin folder?


my login Button Code
thin LoginButton is in admin folder not in root directory the page is login.aspx

protected void btnLog_Click(object sender, EventArgs e)
    {
        String constr = ConfigurationManager.ConnectionStrings["MyProject"].ConnectionString;
        SqlConnection con = new SqlConnection(constr);
        con.Open();

        string sql;
        sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";
        SqlCommand cmd = new SqlCommand(sql,con);
        
        cmd.Parameters.AddWithValue("@UserName", txtU.Text);
        cmd.Parameters.AddWithValue("@Password", txtP.Text);

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        DataTable dt = new DataTable();
        //Session.Timeout = 60;
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            Response.Redirect("~/admin/MainPage.aspx");
        }
        else
        {
            Response.Write("Login failed");
        }
      

    }

推荐答案

嗨sreeCoderMan,



请更新您的查询专线



Hi sreeCoderMan,

Please update your query line

string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";





with





with

string sql;
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "' AND Password ='" + txtP.Text + "'";


您的查询应如下所示



You query should be like below

sql = "SELECT UserName,Password from tblLogin where UserName= @UserName and Password =@Password";
SqlCommand cmd = new SqlCommand(sql,con);
        
        cmd.Parameters.AddWithValue("@UserName", txtU.Text.Trim());
        cmd.Parameters.AddWithValue("@Password", txtP.Text.Trim());





谢谢



Thanks


hi,



问题出现在这一行上



the problem is on this line
sql = "SELECT UserName,Password from tblLogin where UserName= '" + txtU.Text + "', Password ='" + txtP.Text + "'";





你的callling select语句格式不正确。



选择查询是这样的..



your callling select statement that is not correct format.

the select query is like this..

select * from table_name where col_name=condition1 and col_name=condition2





但在您的选择查询中而不是和您的使用(,)。



but in your select query instead of and your using (,).


这篇关于Asp按钮没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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