using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace 登陆
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入用户名:");
string username = Console.ReadLine();
Console.WriteLine("请输入密码:");
string passworld = Console.ReadLine();
//连接字符串
string sqlstr = @"Data Source=BE541554DB7E431;Integrated Security=True";
{
//创建连接对象
using (SqlConnection con = new SqlConnection(sqlstr))
{
//打开数据库
con.Open();
//创建Command命令
using (SqlCommand cmd = new SqlCommand())
{
//先查出表中用户名对应信息
cmd.CommandText = "select *from Ado登陆 where UserName=" + "username";
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())//如果有用户输入的数据就表示存在
{
string dbpassworld = reader.GetString(reader.GetOrdinal("passworld"));
if (passworld == dbpassworld)
{
Console.WriteLine("登陆成功");
}
else
{
Console.WriteLine("登陆失败");
}
}
else
{
Console.WriteLine("用户名或密码错误!");
}
}
}
}
}
}
}
}有问题?没反应,数据是连上了的
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace 登陆
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入用户名:");
string username = Console.ReadLine();
Console.WriteLine("请输入密码:");
string passworld = Console.ReadLine();
//连接字符串
string sqlstr = @"Data Source=BE541554DB7E431;Integrated Security=True";
{
//创建连接对象
using (SqlConnection con = new SqlConnection(sqlstr))
{
//打开数据库
con.Open();
//创建Command命令
using (SqlCommand cmd = new SqlCommand())
{
//先查出表中用户名对应信息
cmd.CommandText = "select *from Ado登陆 where UserName=" + "username";
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())//如果有用户输入的数据就表示存在
{
string dbpassworld = reader.GetString(reader.GetOrdinal("passworld"));
if (passworld == dbpassworld)
{
Console.WriteLine("登陆成功");
}
else
{
Console.WriteLine("登陆失败");
}
}
else
{
Console.WriteLine("用户名或密码错误!");
}
}
}
}
}
}
}
}有问题?没反应,数据是连上了的
解决方案 »
- c#怎么打开任务栏里的QQ
- c# js自动生成文本框,后台如何获取生成后文本框的值
- 蚂蚁在热锅上!!关于网络聊天的问题,大家进来看看
- 寻找.NET案例书籍,网上商店的.
- 用AxImp.exe转换wmp的ActiveX控件是发生错误,高手来看看啊!
- [错误提示]将截断字符串或二进制数据。语句已终止。
- 【请教】请教一个获取网页内容的问题
- treeview为什么不能返回节点总数?
- c# webbrowers给textarea填表,如果直接写在webbrowers是成功的。同样代码在button中就失败了。求怎样在button中不失败。
- 关于拉姆达表达式 的一个问题
- Microsoft OneNote 14.0 类型库怎么没有呢
- 怎么计算代码的运行时间?
=>
cmd.CommandText = "select * from Ado登陆 where UserName='" + username + "'";
=>
cmd.CommandText = "select * from Ado登陆 where UserName='" + username + "'";
这个是错误的,你看一下
cmd.CommandText="select * from ado-登录 where UserName='"+ username+ "'";