晕呢,把取出来的值不绑定到datagrid上,而是把放到数据集里,然后在放入数据库中~~~
只可惜我不晓得怎么从Eexl中读书数据!~
上面那个仁兄 能否告知一二~~`
我是不明白那几段代码我应该怎么调用?要添加什么控件在页面文件?
[此贴子已经被作者于2006-12-5 9:54:57编辑过]
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel files(*.xls)|*.xls";
SqlConnection sqlConnection1 = null;
if(openFileDialog.ShowDialog()==DialogResult.OK)
{
string filePath = openFileDialog.FileName;
sqlConnection1 = new SqlConnection();
sqlConnection1.ConnectionString = "server=(local);integrated security=SSPI;initial catalog=Library";
//import excel into SQL Server 2000
/*string importSQL = "SELECT * into live41 FROM OpenDataSource" +
"('Microsoft.Jet.OLEDB.4.0','Data Source=" + "\"" + "E:\\022n.xls" + "\"" +
"; User ID=;Password=; Extended properties=Excel 5.0')...[Sheet1$]";*/
//export SQL Server 2000 into excel
string exportSQL = @"EXEC master..xp_cmdshell
'bcp Library.dbo.live41 out " + filePath + "-c -q -S" + "\"" + "\"" +
" -U" + "\"" + "\"" + " -P" + "\"" + "\"" + "\'";
try
{
sqlConnection1.Open();
//SqlCommand sqlCommand1 = new SqlCommand();
//sqlCommand1.Connection = sqlConnection1;
//sqlCommand1.CommandText = importSQL;
//sqlCommand1.ExecuteNonQuery();
//MessageBox.Show("import finish!");
SqlCommand sqlCommand2 = new SqlCommand();
sqlCommand2.Connection = sqlConnection1;
sqlCommand2.CommandText = exportSQL;
sqlCommand2.ExecuteNonQuery();
MessageBox.Show("export finish!");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
if(sqlConnection1!=null)
{
sqlConnection1.Close();
sqlConnection1 = null;
}
我也是COPY的别人的,漫漫研究吧~~~