1. 程式人生 > >Csharp: read Sybase SQL anywhere5.5 using c#

Csharp: read Sybase SQL anywhere5.5 using c#

lec oid info clu dbf click nec select post

技術分享圖片

  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());
            }
        }

讀取數據如下:  

技術分享圖片

Csharp: read Sybase SQL anywhere5.5 using c#