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

关于登录有关问题

2012-09-10 
关于登录问题;C# code public partial class login : System.Web.UI.Page{public static string strCon

关于登录问题;

C# code
 public partial class login : System.Web.UI.Page    {        public static string strCon = "server= .; uid=sa; pwd=sa; database=hager";        protected void Page_Load(object sender, EventArgs e)        {        }        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)        {            string sqlsel = "select count(*) from tUser where fCode='" + TextBox1.Text + " and fPassword='" + TextBox2.Text + "''";            SqlConnection con = new SqlConnection(strCon);            con.Open();            SqlCommand com = new SqlCommand(sqlsel, con);                                 if (Convert.ToInt32(com.ExecuteScalar())> 0)            {                RegisterStartupScript("", "<script>alert('登录成功!')</script>");            }            else            {                RegisterStartupScript("", "<script>alert('登录失败!')</script>");            }        }    }



如上所示,简单的登陆问题。但是输入密码会出现用户代码未处理的提示,在数据库执行的话不是〉0就是=0;
但是我调试的时候在密码框输入任何东西都会抱错,求解决。

[解决办法]
单引号问题
C# code
" and fPassword='" + TextBox2.Text + "''"; 

热点排行