C#使用MySQLDriverCS連接MySQL數據庫的代碼片段

wen5 9年前發布 | 3K 次閱讀 C#

MySQLDriverCS下載地址: http://go.rritw.com/sourceforge.net/projects/mysqldrivercs/

static void Main(string[] args)
        {
            MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("127.0.0.1","student", "root", "root",3306).AsString);
            conn.Open();

        MySQLCommand cmd = new MySQLCommand("select * from stuinfo", conn);
        DbDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine(reader.GetString(0) + " " + reader.GetString(1) + " " + reader.GetString(2) + " " + reader.GetString(3));//讀出查詢的結果  
        }
        Console.ReadKey();
        reader.Close();
        conn.Close();//關閉連接  
    }</pre> 


 本文由用戶 wen5 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!