zoukankan      html  css  js  c++  java
  • C#连接数据库的方法

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    namespace 登录
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void btnno_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            private void btnyes_Click(object sender, EventArgs e)
            {
                SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
                scsb.DataSource = "127.0.0.1";
                scsb.UserID = "sa";
                scsb.Password = "123456";
                scsb.InitialCatalog = "studb";
                SqlConnection conn = new SqlConnection(scsb.ToString());//参数:连接数据库的字符串
                if(conn.State==System.Data.ConnectionState.Closed)//判断连接的开启状态
                conn.Open();
                string userid=txtUser.Text.Trim();
                string owd = txtPwd.Text.Trim();
                string strSQL = "select owd from userinfo where [userid]='"+userid+"'";
                SqlCommand comm = new SqlCommand(strSQL,conn);
                SqlDataReader dr = comm.ExecuteReader();
                if(dr.Read())
                {
                    if ((string)dr["owd"] == owd)
                        MessageBox.Show("成功");
                    else
                        MessageBox.Show("错误");
                }
                else
                {
                    MessageBox.Show("不存在");
                }
            }
        }
    }
  • 相关阅读:
    Java可重入锁ReentrantLock
    Java异步编程
    机器学习 pipeline
    Python 机器学习 唐宇迪泰坦尼克号【最新代码】
    引用sklearn报错ImportError: cannot import name 'cross_validation'
    python机器学习-模型优化(六)
    python机器学习-模型评估(五)
    python机器学习-建模(四)
    python机器学习-特征工程(三)
    Python机器学习-数据预处理(二)
  • 原文地址:https://www.cnblogs.com/lxabner/p/12322443.html
Copyright © 2011-2022 走看看