C#连接ODBC数据源的方法
本文实例讲述了C#连接ODBC数据源的方法。分享给大家供大家参考。具体实现方法如下:
//Namespaces,variables,andconstants
usingSystem;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Data.Odbc;
privatevoidCButton_Click(objectsender,System.EventArgse)
{
//CreatetheDataAdapter.
Stringsql="SELECTID,NameFROMProducts";
OdbcDataAdapterda=newOdbcDataAdapter(sql,ConfigurationSettings.AppSettings["connectionstring1"]);
//Createthetable,fillit,andbindthedefaultviewtothegrid.
DataTabledt=newDataTable();
da.Fill(dt);
}
希望本文所述对大家的C#程序设计有所帮助。