电子表格:
string conn = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + Server.MapPath("book1.xls") + ";Extended Properties=Excel 8.0;";
OleDbConnection oleconn = new OleDbConnection(conn);
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source=d:\\book1.xls;Extended Properties=Excel 8.0");
OleDbConnection conn = new OleDbConnection("provider=Microsoft.jet.oledb.4.0;data source="+Server.MapPath("book1.xls")+";Extended Properties=Excel 8.0");
OleDbDataAdapter database = new OleDbDataAdapter("select * from [sheet1$]", oleconn);
access数据库:
conn = new OleDbConnection("Provider=Microsoft.jet.oledb.4.0; Data source=|datadirectory|fileinfo.mdb;jet oledb:database password=mengjiawu;User id=admin");
string conn = "Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + Server.MapPath("monkey.mdb") + "";
OleDbConnection oleconn = new OleDbConnection(ConfigurationManager.AppSettings["accessCon"]);
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=|datadirectory|monkey.mdb");
OleDbConnection conn = new OleDbConnection("provider=microsoft.jet.oledb.4.0;jet oledb:database password=123;user id=admin;data source=" + Server.MapPath("monkey.mdb"));
<connectionStrings>
<add name="connStr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Example.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
sql数据库
SqlConnection conn = new SqlConnection("data source=(local);database=monkey;uid=monkey;pwd=donkey");
SqlDataAdapter database = new SqlDataAdapter("select * from donkey", conn);
sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
server=localhost;database=monkey;uid=monkey;pwd=donkey
server=monkey;database=newssystem;uid=sa;pwd=c0mPuter