C#連接數據庫

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySQLDriverCS;
using System.Windows.Forms;
namespace 清潔生產報告輔助軟件
{
    class Mysql
    {
        public string[] str1;
        public string[] str5;
        public Mysql(string str)
        {
            //得到文本框內容進行檢索
            MySQLConnection conn = null;


            conn = new MySQLConnection(new MySQLConnectionString("localhost", "test", "root", "cao564335").AsString);


            conn.Open();
            String sqlInsert1 = "SELECT COUNT(new1) FROM t_table3";


            // String sqlInsert = "insert into t_table3 values ('1','25','E:\\\\\\\\保存的文件\\\\\\\\3.txt')";




            MySQLCommand commn2 = new MySQLCommand(sqlInsert1, conn);
            commn2.ExecuteScalar();
            string str2 = commn2.ExecuteScalar().ToString();
            int v1 = Convert.ToInt32(str2);
            this.str1 = new string[v1];
            this.str5 = new string[v1];
            MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
            commn.ExecuteNonQuery();
            string sd = "select new3,new2  from  t_table3 where new3  like'" + "%" + str + "%'";//進行查找
            MySQLCommand cmd = new MySQLCommand(sd, conn);//


            MySQLDataReader dr = cmd.ExecuteReaderEx();
            int i = 0;
            while (dr.Read())
            {
                this.str1[i] = dr[0].ToString();
                this.str5[i] = dr[1].ToString();
                i++;




            }
            
          // MessageBox.Show("第一個界面" + str5[0]);
          //  MessageBox.Show("第er個界面" + str1[0]);
            dr.Close();
            
            conn.Close();
        }
    }
}
發佈了27 篇原創文章 · 獲贊 9 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章