用户登录界面已做好,想根据数据库a里的user表里的username和password来判断登录是否合法,合法就做下一步,请问这个判断怎么写? 用户登录界面已做好,想根据数据库a里的user表里的username和password来判断登录是否合法,合法就做下一步,请问这个判断怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SqlConnection sqlconn = 。; SqlCommand sqlcomm = new SqlCommand("select id from admin whereusername='"+username+"' and userpwd='"+userpwd+"'", sqlconn); sqlconn.Open(); try { int uid = (Convert.ToInt64)(sqlcomm.ExecuteScalar()); if (uid > 0) { Session["username"] = uname; Session["uid"] = uid; Response.Redirect("Welcome.aspx"); } else { Response.Write("<script language='javascript'>alert('您的用户名或密码错误!');</script>"); } } catch { } finally { sqlconn.Close(); } 其他都挺好,就是Convert.ToInt64有点问题,改成32也不行 Convert.ToInt32有问题??不知道是错在哪??请楼主说清楚点~! OleDbConnection cnn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=E:\\基于窗体的身份验证\\database.mdb"); if (cnn.State == ConnectionState.Closed) { cnn.Open(); } OleDbCommand cmd = new OleDbCommand(); string str = "Select Count(*) from people where user_name='" + username.Text + "'and user_password='" + Password.Text + "'"; cmd.CommandType = CommandType.Text; cmd.CommandText = str; cmd.Connection = cnn; OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader.GetValue(0).ToString() != "1") { msg.Text = "Invalid username and password"; } else { Response.Redirect("tt.aspx"); } } int uid = (Convert.ToInt32)(sqlcomm.ExecuteScalar());'System.Convert.ToInt32(object)' is a 'method' but is used like a 'type' liubinstud(百里透红) 你在哪啊? (Convert.ToInt32)(sqlcomm.ExecuteScalar());括弧去掉Convert.ToInt32(sqlcomm.ExecuteScalar()); MVC学习遇到的错误 请问下关于关闭子窗体刷新父窗体的问题。。麻烦了。。 关于profile的一些摘抄 求助:NullReferenceException: 未将对象引用设置到对象的实例 如何在宿主页面点按钮动态加载用户控件? 使用Infragistics组件的困惑:关于CausesValidation属性 新手提问 编写控件的书籍 Response.Redirec("AA.aspx")和 Server.Transfer("AA.aspx")的区别与联系? asp.net开发的一个关于sql的小问题~ 取Panel里的控件问题 -- RadioButtonList IIS端口被占用怎么解决
SqlCommand sqlcomm = new SqlCommand("select id from admin where
username='"+username+"' and userpwd='"+userpwd+"'", sqlconn);
sqlconn.Open();
try
{
int uid = (Convert.ToInt64)(sqlcomm.ExecuteScalar()); if (uid > 0)
{
Session["username"] = uname;
Session["uid"] = uid;
Response.Redirect("Welcome.aspx");
}
else
{
Response.Write("<script language='javascript'>alert('您的用户名或密码错误!');</script>");
} }
catch
{ }
finally
{
sqlconn.Close();
}
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
OleDbCommand cmd = new OleDbCommand();
string str = "Select Count(*) from people where user_name='" + username.Text + "'and user_password='" + Password.Text + "'";
cmd.CommandType = CommandType.Text;
cmd.CommandText = str;
cmd.Connection = cnn;
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (reader.GetValue(0).ToString() != "1")
{
msg.Text = "Invalid username and password";
}
else
{
Response.Redirect("tt.aspx");
}
}
'System.Convert.ToInt32(object)' is a 'method' but is used like a 'type'
括弧去掉Convert.ToInt32(sqlcomm.ExecuteScalar());