怎么实现点击button1就可以把磁盘上的execl文本文件导入oracle数据库,求代码!!
然后点击button2可以刷新并显示内容
点button3可以把数据存到硬盘上
然后点击button2可以刷新并显示内容
点button3可以把数据存到硬盘上
解决方案 »
- 3.0的扩展方法引来的沉思……
- datagridview可以空行吗
- 为什么会是web.config文件出错呀?先谢谢了!
- 父控件怎么得到子控件的KeyUp消息?
- C#中,如何让系统在查找局域网中的服务器时显示一个进度窗口(查找进程已经做好)
- C# Winform 读取自定义二进制文件动态生成导航树
- 请问有谁遇到过要同时查询excel表格和数据库中的表
- 请教:在学习对图片加水印,不知道从哪里入手。
- 还是读文件的问题,再请大家帮忙看看~~
- ● 请问在VC#里让dataGrid只显示DataSet的一些列?
- wpf中Listview如何可编辑?搞了半天了也没弄出来
- 寻找用于 Windows Mobile 5.0 Pocket PC SDK 的插件
2.要把数据库的表要导入的列列出来
3.设置好对应关系,然后自己写语句
还要考虑字段类型转换,
自己改改就能用了
代码:
导出:
protected void Button2_Click(object sender, EventArgs e)
{
ToExcel1(DataGrid1, "sikezx.xls");
}
private void ToExcel1(Control ctl, string FileName)
{
Response.Clear();
Response.Buffer = false;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=phone.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End(); }
导入,是加入到datagrid中,至于怎么加入到数据库,简单了吧
protected void Button7_Click(object sender, EventArgs e)
{
try
{
System.IO.FileInfo flf = new System.IO.FileInfo(File1.PostedFile.FileName);
string filename = flf.FullName;
string strCon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + filename + ";Extended Properties=Excel 8.0;";
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [phone$A:N] ";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[phone$A:N]");
myConn.Close();
DataGrid1.DataMember = "[phone$A:N]";
DataGrid1.DataSource = myDataSet;
DataGrid1.DataBind();
}
catch (Exception ex) { }
}
blog.csdn.net/yistudio
1.通过文件上传将客户机上的excel文件上传到服务器端,然后可以通过excel的com组件遍历excel将其数据一行一行的读出来.读出来后insert到数据库中即可
2...........................................,利用oledb直接读取excel到datatable中,然后遍历datatable入库.