private void button1_Click(object sender, EventArgs e) { try { //OdbcConnection conn = new OdbcConnection(); //conn.ConnectionString = // "ODBC;" + // "Driver={Sybase SQL Anywhere 5.0};" + // "DefaultDir=c:\myfolder\;" + // "Dbf=c:\mypath\dbname.db;" + // "Uid=UserName;" + // "Pwd=Secret;" + // "Dsn="""";"; // Must be included! //conn.Open(); geovindu connectionString = "DSN=geovindu;UID=dba;PWD=sql;"; //Data Source=sademo using (OdbcConnection connection = new OdbcConnection(connectionString)) { connection.Open(); DataTable dt = new DataTable();// connection.GetSchema(); DataSet ds = new DataSet(); OdbcDataAdapter da = new OdbcDataAdapter("SELECT * FROM employee", connection); da.Fill(ds); dt = ds.Tables[0]; // Do work here. this.dataGridView1.DataSource = dt; } } catch (OdbcException ex) { MessageBox.Show(ex.Message.ToString()); } }
讀取數据如下:
原文地址:https://www.cnblogs.com/geovindu/p/8431988.html
时间: 2024-10-09 19:33:57