⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginform.cs

📁 主要实现仓库的入库与出库的基本功能
💻 CS
字号:
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 Elysian
{
    public partial class loginForm : Form
    {
        SqlConnection sqlconn;
        SqlDataAdapter adapter;
        DataSet ds = new DataSet();
        public loginForm()
        {
            InitializeComponent();
        }

        private string GetConnectionString()
        {
            return "data source=.;initial catalog=ElysianDB;integrated security=true;User ID=帐号;Password=密码;";
        }

        private void dispalyDB()
        {
            sqlconn = new SqlConnection(GetConnectionString());
            SqlCommand sqlcomm = new SqlCommand("select * from 用户表", sqlconn);
            adapter = new SqlDataAdapter(sqlcomm);
            sqlconn.Open();
            ds.Clear();
            adapter.Fill(ds, "用户表");
            //dataGridView1.DataSource = ds.Tables["用户表"];

            sqlconn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string insertstr = string.Format("insert into 用户表 values('{0}','{1}','{2}')",textBox1.Text,textBox2.Text,textBox3.Text);
            SqlCommand sqlcomm = new SqlCommand(insertstr,sqlconn);
            sqlconn.Open();
            try
            {
                sqlcomm.ExecuteNonQuery();
                MessageBox.Show("恭喜你注册成功!");

                Form1 form = new Form1();
                form.Show();
                this.Hide();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message, "请正确填写!", MessageBoxButtons.OK);
            }
            sqlconn.Close();
            dispalyDB();
        }

        private void loginForm_Load(object sender, EventArgs e)
        {
            dispalyDB();
        }

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

        private void loginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -