您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 登录有数据库连接窗口
  所属分类: C#
  开发工具:
  文件大小: 908byte
  下载次数: 0
  上传时间: 2011-12-16
  提 供 者: o1099******
 详细说明: 很简单!刚学的!有登录和注册using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication2 { public partial class Form1 : Form { SqlConnection conn = null; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try{ SqlCo mmand com = conn.CreateCommand(); string users = textBox1.Text; string password = textBox2.Text; com.CommandText = "select * from T_login where LOGIN_user='"+users+"'"; SqlDataReader reader = com.ExecuteReader(); if (reader.Read()) { //用户名正确! string dbpassword = reader.GetString(reader.GetOrdinal("LOGIN_password")); if (password == dbpassword) { MessageBox.Show("登陆成功!"); } else { MessageBox.Show("密码错误!"); } } else { MessageBox.Show("用户名错误!"); } reader.Close(); } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void Form1_Load(object sender, EventArgs e) { string connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"; try { conn = new SqlConnection(connString); conn.Open(); MessageBox.Show("成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { conn.Dispose(); } private void button3_Click(object sender, EventArgs e) { try { SqlCommand com = conn.CreateCommand(); string users = textBox1.Text; string password = textBox2.Text; com.CommandText = "select * from T_login"; SqlDataReader reader = com.ExecuteReader(); label3.Text = "id,用户名,密码\n"; while (reader.Read()) { label3.Text = label3.Text +"\n"+ string.Format("{0},{1},{2}", reader[0], reader[1], reader[2]); } reader.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button2_Click(object sender, EventArgs e) { try { SqlCommand com = conn.CreateCommand(); string users = textBox1.Text; string password = textBox2.Text; com.CommandText = "select * from T_login where LOGIN_user='" + users + "'"; SqlDataReader reader = com.ExecuteReader(); if (reader.Read()) { //用户名存在! MessageBox.Show("用户名已经存在"); reader.Close(); } else { reader.Close(); //可以注册 com.CommandText = "INSERT INTO T_login (LOGIN_user, LOGIN_password) VALUES ('"+users+"', '"+password+"')"; com.ExecuteNonQuery(); MessageBox.Show("注册成功!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 有数据库连接
 输入关键字,在本站1000多万海量源码库中尽情搜索: