小弟刚刚学习使用asp.net,做了一个简单的登录程序,但数据库搞了很久就连接不上。请各位指教,感激不尽。以下是代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace entry1
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtUsername;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Button btnlogin;
protected System.Web.UI.WebControls.Button btnregister;
protected System.Web.UI.WebControls.Label message;
protected System.Web.UI.WebControls.TextBox txtPassword;
private void Page_Load(object sender, System.EventArgs e)
{
string strsql="";
DataSet ds = new dataset();
string sqlConnstr="data source=(local);initial catalog=competence;persist security info=Fasle;user id=stone;pwd=;workstation id=mywork;pack size=4096;min pool size=0;size=200;max pool size=200";
Sqlconnection SqlConn= new Sqlconnection(sqlConnStr);
sqlConn.Open();
SqlDataAdapter sqlAdapter = new SqlDataAdapter(strSql,sqlConn);
sqlAdapter.Fill(ds,"sql");
sqlConn.Close();
}
private void InitializeComponent()
{
}
private void btnlogin_Click(object sender, System.EventArgs e)
{
string sql = "SELECT Userid FROM competence WHERE UserName=txtUserName.text AND UserPassword=txtPassword.Text";
if (UserName=txtUserName.text)
{
if(UserPassword=txtPassword.Text)
{
Response.Redirect("afterlogin.aspx");
}
else
{
message.Text="Wrong password!";
}
}
else
{
message.Text="Illegal user!";
}
}
}
}
[此贴子已经被作者于2006-8-14 16:35:51编辑过]