工作忙,没有时间完成毕业设计,望大家帮忙!
c#2005的好处就是控件添加后不用声明,本代码包含两个textbox,一个linkbutton,
数据库是sql2005,如果你是2000的数据库可能会有问题!
using System;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
string yzConnStr = "Data Source=YH02\\SQLEXPRESS;Initial Catalog=network_course;User ID=sa;Password=aaaaaa";
SqlConnection yzCon = new SqlConnection(yzConnStr);
yzCon.Open();
string SQLStr = "SELECT * FROM userT where name='" + TextBox2.Text + " 'and password='" + TextBox1.Text + " '";
SqlCommand yzcmd = new SqlCommand(SQLStr, yzCon);
SqlDataReader rd;
rd = yzcmd.ExecuteReader();
string s;
if (rd.Read())
{
s = rd[0].ToString();
if (s == null)
Response.Write("用户名或密码错误,请重新输入!");
else Response.Redirect("Menu.aspx");
}
else Response.Write("用户名或密码错误,请重新输入!");
}
}