请问C#中如何把EXCEL表中的数据添加到数据库中
请问C#中如何把EXCEL表中的数据添加到数据库中
现在有一个EXCEL表 表结构和数据库中相应表结构相同
如何通过程序把它写进数据库相应表里
------解决方案--------------------private void button1_Click(object sender, System.EventArgs e)
{
try
{
string strConnection= " ";
strConnection= "Provider = Microsoft.Jet.OLEDB.4.0; "+ "Data Source = c:\\Book1.xls; "+ "Extended Properties=Excel 8.0; " ;
oleDbConnection1.ConnectionString=strConnection;
oleDbDataAdapter1.SelectCommand.CommandText= "Select * From MySheetName ";
oleDbDataAdapter1.SelectCommand.Connection=oleDbConnection1;
this.oleDbDataAdapter1.Fill(this.dataSet1);
dataGrid1.DataSource=dataSet1;
if (!this.dataGrid1.IsExpanded(0))
{
dataGrid1.Expand(0);
}
}
catch (
System.Exception errr)
{
MessageBox.Show( "Failed ");
}
}
楼主看看!