zoukankan      html  css  js  c++  java
  • .NET连接MySQL和SQL Server数据库

    连接MySQL:

    首先,我们需要下载一个程序包,并解压“MySql.Data.dll”,点击下载

    using MySql.Data.MySqlClient;
    MySqlConnection mycon = new MySqlConnection("server=xxx.xxx.xx.xxx;user id=sa;password=sa;database=Wan");
    mycon.Open();
    MySqlCommand mysqlcom = new MySqlCommand("select Password_ from Person where Username='" + Username + "'", mycon);
    MySqlDataAdapter sda = new MySqlDataAdapter();
    sda.SelectCommand = mysqlcom;
    DataSet ds = new DataSet();
    sda.Fill(ds);
    string Password_ = null;
    try
    {
        Password_ = ds.Tables[0].Rows[0]["Password_"].ToString();
    }
    catch
    {
        return "该账号未注册";
    }
    try
    {
        if (Password_.Equals(Password))
        {
            return "账号和密码正确";
        }
        else
        {
            return "密码错误";
        }
    }
    finally
    {
        mysqlcom.Dispose();
        mycon.Dispose();
        mycon.Close();
    }

    连接SQL Server:

    SqlConnection mycon = new SqlConnection("server=.;database=Wan;uid=sa;pwd=sa");
    con.Open();
    SqlCommand sqlcom = new SqlCommand("select Password_ from Person where Username='" + Username + "'", con);
    SqlDataAdapter sda = new SqlDataAdapter();
    sda.SelectCommand = sqlcom;
    DataSet ds = new DataSet();
    sda.Fill(ds);
    string Password_ = null;
    try
    {
        Password_ = ds.Tables[0].Rows[0]["Password_"].ToString();
    }
    catch
    {
        return "该账号未注册";
    }
    try
    {
        if (Password_.Equals(Password))
        {
            return "账号和密码正确";
        }
        else
        {
            return "密码错误";
        }
    }
    finally
    {
        sqlcom.Dispose();
        con.Dispose();
        con.Close();
    }    


  • 相关阅读:
    Core Foundation框架(2)命名规范,内省
    Core Foundation框架(1)基础介绍
    Swift 数组,字典
    Swift 操作符
    Swift 可选值
    Swift 元组
    Swift 变量声明
    iOS开发_UI_AutoLayout
    iOS开发_Objective-C_字符串操作
    iOS开发_Objective-C_监听搜索时用户输入的拼音
  • 原文地址:https://www.cnblogs.com/wyongqi/p/7498761.html
Copyright © 2011-2022 走看看