欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
C#連接MySql方法有二

1、用MySQLDriverCS連接MySQL數據庫

先下載和安裝MySQLDriverCS,地址:

http://sourceforge.net/projects/mysqldrivercs/

在安裝文件夾下面找到MySQLDriver.dll,然后將MySQLDriver.dll添加引用到項目中

注:我下載的是版本是 MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.Odbc;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using MySQLDriverCS;

 

 

namespace mysql

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

            MySQLConnection conn = null;

            conn = new MySQLConnection(new MySQLConnectionString("localhost", "inv", "root", "831025").AsString);

            conn.Open();

 

            MySQLCommand commn = new MySQLCommand("set names gb2312", conn);

            commn.ExecuteNonQuery();

 

            string sql = "select * from exchange ";

            MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);

 

            DataSet ds = new DataSet();

            mda.Fill(ds, "table1");

 

            this.dataGrid1.DataSource = ds.Tables["table1"];

            conn.Close();

 

        }

 

  

    }

}

 

2、通過(guò)ODBC訪(fǎng)問(wèn)mysql數據庫:

 

參考:http://www.microsoft.com/china/community/Column/63.mspx

 

1.      安裝Microsoft ODBC.net:我安裝的是mysql-connector-odbc-3.51.22-win32.msi

2.      安裝MDAC 2.7或者更高版本:我安裝的是mdac_typ.exe 2.7簡(jiǎn)體中文版

3.      安裝MySQLODBC驅動(dòng)程序:我安裝的是 odbc_net.msi

4.      管理工具 -> 數據源ODBC –>配置DSN…

5.      解決方案管理中添加引用 Microsoft.Data.Odbc.dll(1.0.3300)

6.      代碼中增加引用 using Microsoft.Data.Odbc;

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Linq;   //vs2005好像沒(méi)有這個(gè)命名空間,在c#2008下測試自動(dòng)生成的

using System.Text;

using System.Windows.Forms;

using Microsoft.Data.Odbc;

 

namespace mysql

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

 

            string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +

                                 "SERVER=localhost;" +

                                 "DATABASE=inv;" +

                                 "UID=root;" +

                                 "PASSWORD=831025;" +

                                 "OPTION=3";

            OdbcConnection MyConnection = new OdbcConnection(MyConString);

            MyConnection.Open();

            Console.WriteLine("\n success, connected successfully !\n");

           

            string query = "insert into test values( 'hello', 'lucas', 'liu')";

            OdbcCommand cmd = new OdbcCommand(query, MyConnection);

         

            //處理異常:插入重復記錄有異常

try{

   cmd.ExecuteNonQuery();

}

catch(Exception ex){

                 Console.WriteLine("record duplicate.");

}finally{

                 cmd.Dispose();

}

 

//***********************read方法讀數據到textbox**********************

            string tmp1 = null;

            string tmp2 = null;

            string tmp3 = null;

            query = "select * from test ";

            OdbcCommand cmd2 = new OdbcCommand(query, MyConnection);

            OdbcDataReader reader = cmd2.ExecuteReader();

            while (reader.Read())

            {

                tmp1 = reader[0].ToString();

                tmp2 = reader[1].ToString();

                tmp3 = reader[2].ToString();

            }

            this.textBox1.Text = tmp1 + " " + tmp2 + " " + tmp3;

            */

 

//************************datagridview控件顯示數據表**************************

string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +

                                 "SERVER=localhost;" +

                                 "DATABASE=inv;" +

                                 "UID=root;" +

                                 "PASSWORD=831025;" +

                                 "OPTION=3";

          OdbcConnection MyConnection = new OdbcConnection(MyConString);

OdbcDataAdapter oda = new OdbcDataAdapter("select * from customer ", MyConnection);

DataSet ds = new DataSet();

          oda.Fill(ds, "employee");
          this.dataGridView1.DataSource = ds.Tables["employee"];

*/

 

           MyConnection.Close();

        }

    }

}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
如何在.NET中訪(fǎng)問(wèn)MySQL數據庫 (轉自:http://blog.csdn.net/v...
C#連接mysql資料整理
asp.net如何連接MySQL
asp.net 訪(fǎng)問(wèn)Excel的方法
將dataGridView中的添加/刪除等修改保存至數據庫(winform - VS2005)
ADO.net連接MySQL
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久