excel 导入SQL数据库代码

SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["connStr"].ToString());
SqlCommand cmd = new SqlCommand("",conn);
conn.Open();
cmd.CommandText = "insert into test2 select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Excel 5.0;HDR=YES;DATABASE=f://Price',sheet1$)";
cmd.ExecuteNonQuery();
conn.Close(); 

你可能感兴趣的:(excel 导入SQL数据库代码)