//连接数据库语句。。
SqlConnection sqlcon = new SqlConnection("DataSource=服务器名;Integrated Catalog=数据库名;
Initial Security=True");
//打开数据库
sqlcon.Open();
//从数据库中找出与用户名相符的密码。。。
string sqlcmd = "select * from table where name='"+textBox1.Text.Trim()+"' ";
SqlCommand cmd = new SqlCommand(sql, cn);
SqlDataReader dr = cmd.ExecuteReader();
//读取出来与密码进行比较
if(dr.read())
{
if(dr["Password"]==TextBox2.text)
MessageBox.Show("登录成功!");
}
else
MessageBox.Show("用户名或密码错误!");
dr.Close();
cn.Close();