winForm后台登陆代码 C# winForm窗体的,连接数据库为SQLite实现一个登录页,后台代码给个详细的?分都给了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20080923/13/d567615a-abd5-4ede-a1f3-2d28264988cb.html实现登录和连接什么数据库没有什么直接的联系。根据你的思路来定。 连接字符串自己修改一下就行了using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.Sql;using System.Data.SqlClient;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Xml;namespace stserver{ public partial class login : Form { public login() { InitializeComponent(); } public bool islogin = false; private void btn_submit_Click(object sender, EventArgs e) { try { XmlDocument doc = new XmlDocument(); doc.Load(Application.StartupPath + "\\config.xml"); string connstr = doc.DocumentElement.SelectSingleNode("serverconnstr").InnerText; string selectstr = "select top 1 id from admin where uid='" + txb_uid.Text + "' and pwd='" + txb_pwd.Text + "'"; SqlConnection conn = new SqlConnection(connstr); conn.Open(); SqlCommand cmd = new SqlCommand(selectstr, conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { islogin = true; dr.Close(); conn.Close(); conn.Dispose(); MessageBox.Show("您好," + txb_pwd.Text + "!,欢迎使用\n\n祝您工作愉快!", "欢迎", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { dr.Close(); conn.Close(); conn.Dispose(); MessageBox.Show("登录失败!\n请检查您的登录用户名和密码是否正确。\n\n如果您忘记了自己的密码请联系技术部"); txb_uid.Text = ""; txb_pwd.Text = ""; txb_uid.Focus(); } dr.Close(); conn.Close(); conn.Dispose(); } catch { MessageBox.Show("不能连接到服务器,请联系技术部","服务器故障",MessageBoxButtons.OK,MessageBoxIcon.Error); } } private void btn_cancel_Click(object sender, EventArgs e) { Application.ExitThread(); } }} 需要一个SQLite的引擎啊,有个System.Data.SQLite,添加到项目引用之后就可以用了,给你个简单的参考: SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3"); mycon.Open(); SQLiteCommand cmd = mycon.CreateCommand(); cmd.CommandText = @"select * from person"; SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; mycon.Close(); 装完SQLite后,添加SQLite命名空间using System.Data.SQLite,添加到项目引用之后就可以用了然后将我代码的SqlConnection等相关部分改为SQLiteConnection等就可以了: SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3"); mycon.Open(); SQLiteCommand cmd = mycon.CreateCommand(); cmd.CommandText = @"select * from person"; SQLiteDataAdapter da = new SQLiteDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; mycon.Close(); using (SQLiteConnection conn2 = new SQLiteConnection(connStr)) { conn2.Open(); using (SQLiteCommand cmd1 = new SQLiteCommand("", conn2)) { } }login frmlogin = new login(); if (login.ShowDialog() == DialogResult.OK) { Application.Run(new main_form()); }51aspx.com里 /// <summary> /// 登录系统 /// </summary> private bool Login(string userName, string password) { mainForm = new FormMain(); errorProvider1.Clear(); bool success = false; mainForm.CurrentUser = mainForm.DatabaseAccess.VerifyUser(userName, password); if (mainForm.CurrentUser != null) { mainForm.Show(); this.Hide(); success = true; mainForm.WriteLog("用户登录成功...."); } else { errorProvider1.SetError(cbbUserName, "登录发生错误,错误原因:\r\n 1、用户名或密码错误。请核对后重新登录。\r\n 2、数据库连接不可达,请检查网络连接。"); } return success; } 在线程中,如何读取 设置多控件的操作? asp.net伪静态问题 正则 提取URL后缀参数问题 求救高手! 邮件的重复发送,望能给出建议 在asp.net中如何创建一个ini文件? c#中怎么没有视图 WPF怎么实现ComboBox和Label之间的数据绑定 C# 的web页面中无法获取GridView的源数据 怎么知道机器是否安装了.NET FrameWork? 不要告诉我从安装在机器上的目录来看。 高级问题 鲜有人能回答 利用excel报表作为模板 来软件中显示 高手小跑进 winform生成窗体的定位问题。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;namespace stserver
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
public bool islogin = false; private void btn_submit_Click(object sender, EventArgs e)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath + "\\config.xml");
string connstr = doc.DocumentElement.SelectSingleNode("serverconnstr").InnerText;
string selectstr = "select top 1 id from admin where uid='" + txb_uid.Text + "' and pwd='" + txb_pwd.Text + "'";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand(selectstr, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
islogin = true;
dr.Close();
conn.Close();
conn.Dispose();
MessageBox.Show("您好," + txb_pwd.Text + "!,欢迎使用\n\n祝您工作愉快!", "欢迎", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
dr.Close();
conn.Close();
conn.Dispose();
MessageBox.Show("登录失败!\n请检查您的登录用户名和密码是否正确。\n\n如果您忘记了自己的密码请联系技术部");
txb_uid.Text = "";
txb_pwd.Text = "";
txb_uid.Focus();
}
dr.Close();
conn.Close();
conn.Dispose();
}
catch
{
MessageBox.Show("不能连接到服务器,请联系技术部","服务器故障",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
} private void btn_cancel_Click(object sender, EventArgs e)
{
Application.ExitThread();
}
}
}
SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3");
mycon.Open();
SQLiteCommand cmd = mycon.CreateCommand();
cmd.CommandText = @"select * from person";
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
mycon.Close();
SQLiteConnection mycon = new SQLiteConnection(@"data source=db\Person.db3");
mycon.Open();
SQLiteCommand cmd = mycon.CreateCommand();
cmd.CommandText = @"select * from person";
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
mycon.Close();
{
conn2.Open();
using (SQLiteCommand cmd1 = new SQLiteCommand("", conn2))
{
}
}login frmlogin = new login();
if (login.ShowDialog() == DialogResult.OK)
{
Application.Run(new main_form());
}
51aspx.com里
/// 登录系统
/// </summary>
private bool Login(string userName, string password)
{
mainForm = new FormMain();
errorProvider1.Clear();
bool success = false;
mainForm.CurrentUser = mainForm.DatabaseAccess.VerifyUser(userName, password);
if (mainForm.CurrentUser != null) { mainForm.Show(); this.Hide(); success = true; mainForm.WriteLog("用户登录成功...."); }
else
{
errorProvider1.SetError(cbbUserName, "登录发生错误,错误原因:\r\n 1、用户名或密码错误。请核对后重新登录。\r\n 2、数据库连接不可达,请检查网络连接。");
}
return success;
}