本文整理汇总了C#中System.Data.Odbc.OdbcDataAdapter类的典型用法代码示例。如果您正苦于以下问题:C# OdbcDataAdapter类的具体用法?C# OdbcDataAdapter怎么用?C# OdbcDataAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OdbcDataAdapter类属于System.Data.Odbc命名空间,在下文中一共展示了OdbcDataAdapter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDataSetFromAdapter
public DataSet GetDataSetFromAdapter(
DataSet dataSet, string connectionString, string queryString)
{
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
OdbcDataAdapter adapter =
new OdbcDataAdapter(queryString, connection);
// Open the connection and fill the DataSet.
try
{
connection.Open();
adapter.Fill(dataSet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
return dataSet;
}
示例2: new OdbcDataAdapter(String sql, OdbcConnection con);
//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.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();
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 8);
this.dataGrid1.Size = new System.Drawing.Size(376, 288);
this.dataGrid1.TabIndex = 0;
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();
}
}