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("不存在");
                }
            }
        }
    }
  • 相关阅读:
    微信小程序promise解决onload异步
    小程序中使用 Less (VScode)
    Vue中使用less
    小程序获取 图片宽高
    ssh 登录出现Are you sure you want to continue connecting (yes/no)?解决方法
    SQL SERVER 收缩日志
    SQL SERVER-日期时间
    oracle判断查询结果是否为空
    修改Tomcat默认JDK版本
    Microsoft SQL Server Management Studio ------- 附加数据库 对于 服务器“xxx"失败(错误码5120)
  • 原文地址:https://www.cnblogs.com/lxabner/p/12322443.html
Copyright © 2011-2022 走看看