using System; using System.Collections.Generic; using System.Text; using System.Data.Odbc; namespace ConnectExcel { class Program { static void Main(string[] args) { OdbcConnection con = new OdbcConnection(@\"Driver={Microsoft Excel Driver (*.xls)};DBQ=Excel/student.xls\"); // OdbcDataAdapter da=new OdbcDataAdapter(); OdbcCommand com = new OdbcCommand(\"select stuid,stuname from [student$]\", con); con.Open(); OdbcDataReader dr = com.ExecuteReader(); while (dr.Read()) { Console.WriteLine(dr[0]); Console.WriteLine(dr[1]); } dr.Close(); con.Close(); } } }
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc; namespace ConnectExcel
{
class Program
{
static void Main(string[] args)
{
OdbcConnection con = new OdbcConnection(@\"Driver={Microsoft Excel Driver (*.xls)};DBQ=Excel/student.xls\");
// OdbcDataAdapter da=new OdbcDataAdapter(); OdbcCommand com = new OdbcCommand(\"select stuid,stuname from [student$]\", con);
con.Open();
OdbcDataReader dr = com.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[0]);
Console.WriteLine(dr[1]);
}
dr.Close();
con.Close(); }
}
}