用c#做个登陆,要求是登陆界面的用户名和密码要求检查数据库理有没有,有才可以登陆。越简单越好。

来源:百度知道 编辑:UC知道 时间:2024/06/26 06:27:23

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
String connectString="这里填你的连接字符串";
SqlConnection conn = new SqlConnection(connectString);
SqlCommand command=new SqlCommand(conn);
command.CommandText = "select * from users where name='小明' and password='123'"; //查询表里面的记录
conn.Open();
SqlDataReader read = command.ExecuteReader();
if (read.HasRows())//判断名字是小明,密码为123的数据行是否存在
{
Console.WriteLine("登陆成功");/*控制台程序输出,如果要在窗体或者/网页输出登陆成功的话,相似!*/
}
else
{
Console.WriteLine("登陆失败");
}
}
}
}

二楼的程序是有问题的,你自己试试就知道了~~写了这么多注释,应该给分了吧。有什么不明白的,再问!!

投入

using System;
using System.Collections.Generic;
using System.Text;
using Sys