new OdbcConnection连接核心代码
private void MainClass_Load(object sender, System.EventArgs e)
{
string connectionString = @"Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;";OdbcConnection conn= new OdbcConnection(connectionString);
conn.Open();OdbcDataAdapter da = new OdbcDataAdapter ("SELECT CustomerID, ContactName, ContactTitle FROM Customers", conn);
DataSet ds = new DataSet("Cust");
da.Fill(ds, "Customers");dataGrid1.DataSource = ds.DefaultViewManager;
conn.Close();
}
下面为详细实例
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Data.Odbc;public class MainClass : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;public MainClass()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(376, 288);
this.dataGrid1.TabIndex = 0;
//
// MainClass
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(384, 302);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.dataGrid1});
this.Load += new System.EventHandler(this.MainClass_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);}
[STAThread]
static void Main()
{
Application.Run(new MainClass());
}private void MainClass_Load(object sender, System.EventArgs e)
{
string connectionString = @"Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;";OdbcConnection conn= new OdbcConnection(connectionString);
conn.Open();OdbcDataAdapter da = new OdbcDataAdapter ("SELECT CustomerID, ContactName, ContactTitle FROM Customers", conn);
DataSet ds = new DataSet("Cust");
da.Fill(ds, "Customers");dataGrid1.DataSource = ds.DefaultViewManager;
conn.Close();
}
}
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级