C#连接数据库 用户登录
来源:互联网 发布:知秋的小说 太惨 编辑:程序博客网 时间:2024/05/17 00:57
方法1:
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["testConnectionString"].ToString();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connStr;
conn.Open();
string sql = "select * from admin where username='" + u1 + "' and password='" + p1 + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
bool bl = cmd.ExecuteScalar() == null ? true : false;
conn.Close();
if (bl == false) Response.Write("登录成功!");
else Response.Write("登录失败");
方法2:
string sql = "server=localhost;database=test;uid=sa;pwd=123456"; SqlConnection con = new SqlConnection(sql); //连接数据库 // SqlDataAdapter oda = new SqlDataAdapter("select * from where text_No='" + TextBox1.Text + "'and pwd='" + TextBox2.Text + "'",con); //构造SQL语句,该语句在RegUsers表中检查昵称和密码是否正确 string str = "select * from admin where username='" + u1 + "'and password='" + p1 + "'"; con.Open(); // 打开连接 SqlCommand cmd = new SqlCommand(str, con); // 创建Command对象 SqlDataReader dr = cmd.ExecuteReader(); // 执行ExecuteReader()方法 if (dr.Read()) { //Response.Redirect("text2.aspx"); Response.Write("登录成功!"); } else { Response.Write("登录失败"); } dr.Close(); con.Close();
- C#连接数据库 用户登录
- C#登录信息连接数据库
- c#中连接数据库关于sqlconnection的用户sa无法登录的问题
- Unity C# 连接SQL Server数据库,实现获取和添加登录注册的用户列表
- Winform连接数据库并实现用户登录
- struts2连接数据库实现用户登录
- jsp连接数据库实现用户登录功能
- jsp连接数据库实现用户登录功能
- 基于数据库的C#用户登录程序
- vs.net C# 连接数据库 出现错误 用户 '(null)' 登录失败。原因: 未与信任 SQL Server 连接相关联
- 用python连接数据库,实现用户注册和用户登录
- C# 连接ACCESS 验证用户登录,读取SESSION值
- Winform连接SQL数据库并实现用户登录
- struts2连接数据库实现用户注册与登录
- 使用CAS登录模块连接数据库验证用户合法性
- MyEclipse下jsp连接mysql数据库实现用户登录
- ADO.NET 使用Connection对象连接数据库实现用户登录
- eclipse连接数据库时:“用户XX 登录失败”
- 从今天起,每天认真阅读CSDN
- 5款免费的优秀网站配色方案工具
- Shell编程基础
- Error while running application engine programs during installation
- ubuntu快捷键
- C#连接数据库 用户登录
- 将x中从第p位开始的n个(二进制)位设置为y中最右边n位的值,x的其余各位保持不变
- poj 2387 Til the Cows Come Home
- Mvvm Light Toolkit for wpf/silverlight系列之搭建mvvmlight开发框架
- VC++6.0中错误"unexpected end of file while looking for precompiled...
- 字符编码格式小结(ASCII/Unicode/UTF-8)
- HDU 1728 一条路走到底
- 用Intellij Idea 10.0.0.3写一个JAVA ME的测试程序
- C++循环变量定义生命周期