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("不存在");
                }
            }
        }
    }
  • 相关阅读:
    持续集成 最佳实践 研讨会(1月25日 广州)
    Selenium自动化测试项目案例实践公开课
    自动化测试管理平台ATMS(V2.0.3_8.28)下载
    自动化测试管理平台ATMS(V2.0.2_8.19)下载
    最近的免费软件测试课程
    Ranorex入门指南
    圆满完成Selenium自动化测试周末班培训课程!
    自动化测试管理平台ATMS(V2.0.1_8.12)下载
    GradNet: Gradient-Guided Network for Visual Object Tracking阅读笔记
    Distilling Object Detectors with Fine-grained Feature Imitation阅读笔记
  • 原文地址:https://www.cnblogs.com/lxabner/p/12322443.html
Copyright © 2011-2022 走看看