• 大小: 397KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C#
  • 标签: c#  用户登录  数据库  

资源简介

当时随手做的一个小程序 ,C#连接sql 2000数据库的用户登录。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 登录测试
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }

        private void button2_Click(object sender EventArgs e)
        {
             this.Close();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //int k;
            string CString = “ Data Source=PC-346121294017\\SQL;Initial Catalog=53;Integrated Security=True;“;
            string sql = “select top 1 * from 用户登录 where 用户名=‘“+comboBox1.Text .Trim ()+“‘and 密码=‘“+textBox1 .Text .Trim ()+“‘“;
            SqlConnection Mycon = new SqlConnection(CString);
            Mycon.Open();
            SqlCommand Mycom = new SqlCommand(sql Mycon);
            //Mycom.Connection = Mycon;
            //Mycom.CommandType = CommandType.Text;
            //Mycom.CommandText = sql;

           // k = Mycom.ExecuteNonQuery();
            SqlDataReader dr = Mycom .ExecuteReader ();
            
            if (dr.Read())
            { 
                button2.Enabled = true; 
            }
            else
            {
                MessageBox.Show(“密码错误“ “提示“); 
            }
            Mycon.Close();
           

            
            
        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {
            
        }

        private void Form1_Load(object sender EventArgs e)
        {
            button2.Enabled = false;
            int k;
            string CString = “ Data Source=PC-346121294017\\SQL;Initial Catalog=53;Integrated Security=True;“;
            string SQLStr = “select 用户名 from 用户登录“;

            SqlConnection Mycon = new SqlConnection(CString);
            Mycon.Open();
            SqlCommand Mycom = new SqlCommand();
            Mycom.Connection = Mycon;
            Mycom.CommandType = CommandType.Text;
            Mycom.CommandText = SQLStr;
            k = Mycom.ExecuteNonQuery();

            SqlDataAdapter adp = new SqlDataAdapter(SQLStr Mycon);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            comboBox1.DataSource = ds.Tables[0].DefaultView;
            comboBox1.DisplayMember = “用户名“;
            comboBox1.ValueMember = “用户名“;

            comboBox2.DataSource = ds.Tables[0].DefaultView;
            comboBox2.DisplayMember = “用户名“;
            comboBox2.ValueMember = “用户名“;
            Mycon.Close();
            
        }

        private void button3_Click(object sender EventArgs e)
        {
            int k1;
            string CString = “ Data Source=PC-346121294017\\SQL;Initial Catalog=53;Integrated Security=True;“;
            string sqlstr = “insert into 用户登录(用户名密码) val

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1504  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.application

     文件      28672  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.exe

     文件       2150  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.exe.manifest

     文件      34304  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.pdb

     文件     423936  2012-12-13 11:08  登录测试\登录测试\bin\Debug\登录测试.publish\setup.exe

     文件       5305  2012-12-13 11:08  登录测试\登录测试\bin\Debug\登录测试.publish\登录测试.application

     文件      24576  2012-12-13 11:08  登录测试\登录测试\bin\Debug\登录测试.publish\登录测试_1_0_0_0\登录测试.exe.deploy

     文件       5894  2012-12-13 11:08  登录测试\登录测试\bin\Debug\登录测试.publish\登录测试_1_0_0_0\登录测试.exe.manifest

     文件       1504  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.vshost.application

     文件       5632  2005-12-08 14:51  登录测试\登录测试\bin\Debug\登录测试.vshost.exe

     文件       2150  2012-12-17 09:57  登录测试\登录测试\bin\Debug\登录测试.vshost.exe.manifest

     文件       7329  2012-12-17 09:57  登录测试\登录测试\Form1.cs

     文件      19240  2012-12-17 09:51  登录测试\登录测试\Form1.Designer.cs

     文件       5814  2012-12-17 09:51  登录测试\登录测试\Form1.resx

     文件       1504  2012-12-17 09:57  登录测试\登录测试\obj\Debug\登录测试.application

     文件        842  2012-12-17 09:51  登录测试\登录测试\obj\Debug\登录测试.csproj.GenerateResource.Cache

     文件      28672  2012-12-17 09:57  登录测试\登录测试\obj\Debug\登录测试.exe

     文件       2150  2012-12-17 09:57  登录测试\登录测试\obj\Debug\登录测试.exe.manifest

     文件        180  2012-12-17 09:51  登录测试\登录测试\obj\Debug\登录测试.Form1.resources

     文件      34304  2012-12-17 09:57  登录测试\登录测试\obj\Debug\登录测试.pdb

     文件        180  2012-12-11 15:49  登录测试\登录测试\obj\Debug\登录测试.Properties.Resources.resources

     文件        449  2013-02-26 11:33  登录测试\登录测试\obj\登录测试.csproj.FileList.txt

     文件        471  2012-12-11 15:46  登录测试\登录测试\Program.cs

     文件       1224  2012-12-11 15:46  登录测试\登录测试\Properties\AssemblyInfo.cs

     文件       2878  2012-12-11 15:46  登录测试\登录测试\Properties\Resources.Designer.cs

     文件       5612  2012-12-11 15:46  登录测试\登录测试\Properties\Resources.resx

     文件       1095  2012-12-11 15:46  登录测试\登录测试\Properties\Settings.Designer.cs

     文件        249  2012-12-11 15:46  登录测试\登录测试\Properties\Settings.settings

     文件     423936  2012-12-13 11:08  登录测试\登录测试\publish\setup.exe

     文件       5305  2012-12-13 11:08  登录测试\登录测试\publish\登录测试.application

............此处省略23个文件信息

评论

共有 条评论