登陆
来源:互联网 发布:淘宝小说 编辑:程序博客网 时间:2024/05/17 04:44
-----------------------------配置文件---------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="sql" connectionString="server=.;database=MySecondDB;uid=sa;pwd=520;"/>
</connectionStrings>
</configuration>
----------------------------Program.cs------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _08登陆
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
-----------------------------Form1-------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _08登陆
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
// 如何表示登陆成功了
string uid = txtUid.Text.Trim();
string pwd = txtPwd.Text;
// 验证
string connStr = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
string sql = "select count(*) from loginPrimaryTest where uid= '" + uid + "' and pwd='" + pwd + "'";
int count;
using (SqlConnection conn = new SqlConnection(connStr))
{
// 执行对象
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
count = (int)cmd.ExecuteScalar();
}
}
if (count > 0)
{
MessageBox.Show("登陆成功");
}
else
{
MessageBox.Show("用户名或密码错误");
}
}
}
}
遇到的问题: 发现添加 using System.Configuration 后 ConfigurationManager 依然无效
解决的方法: 在项目的 Reference 中 添加 System.Configuraton
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 登陆
- 第一次登陆!!
- 第一次登陆
- 首次登陆
- 第一次登陆
- 初次登陆
- 第一次登陆
- 单点登陆
- SDKD 2016 Winter Single Training B, div2 出题总结
- Codeforces 119C Education Reform【dp+路径输出】
- 菜鸟之路——Spring MVC(三)DispatcherServlet详解
- TOMCAT服务器不写端口号、不写项目名访问项目、虚拟目录配置
- mysql允许远程访问
- 登陆
- 71颜色方块(5)84(6)97(7)108(8)
- Java构建器
- Eclipse Class Decompiler——Java反编译插件
- ubuntu下安装python的Tkinter库
- CSS选择器参考手册(转自w3school)
- 【c++/数据结构】哈希表
- 学习Android Architecture Blueprints(四)-databinding分支
- LeetCode 357 Count Numbers with Unique Digits (排列组合)