我有一张表比如说 表名test
有ID NAME TYPE 这3个字段 我在excel中 写了 编号 名称 类型这3个列头。现在我想在EXCEL中填写对应字段的内容 然后将它倒进数据库对应的test表中(.net技术) 或者是有没办法不通过程序直接倒 哪为仁兄给点办法
有ID NAME TYPE 这3个字段 我在excel中 写了 编号 名称 类型这3个列头。现在我想在EXCEL中填写对应字段的内容 然后将它倒进数据库对应的test表中(.net技术) 或者是有没办法不通过程序直接倒 哪为仁兄给点办法
解决方案 »
- ASP.NET控件如何添加name属性
- 我们网站集成了支付宝的即时到帐接口,现在我想换成标准双接口,怎么办?
- 急!Login控件的访问问题
- aspx如何过滤表单里的sql特殊字符,例如单引号,分号?
- 怎么连接mysql数据库
- 求:MSDN 上 ASP.NET中DataGrid的高级技巧 讲座 演示原代码!!!
- 老瓶装新酒
- 很多网站都有专题,想了解一下专题实现的思路与方法!!
- listbox在多选情况下,如果想把那些选中的项目都删除,该功能应如何编写。
- 如何实现包含公用模块
- Textarea作为服务器运行后出现的奇怪问题
- 有一个这样的需求.....大家帮助下如何实现^^^^^^^^^^^^^^^^^^^^^^^^^^^^
然后再Insert into
string strPath=MapPath("ImportData");
string FileName=strPath+"\\"+"PIWS.xls";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+FileName+";Extended Properties=Excel 8.0;";
string sql = "Select '' as ID,Item,'' as SO,Date,Line,Qty,SO from [PIWS$]";
System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection( connectionString );
System.Data.OleDb.OleDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter( sql, connection );
System.Data.DataSet dataSet = new DataSet();
connection.Open();
dataAdapter.Fill( dataSet, "PIWS" );
connection.Close();
FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
string path = FileUpload1.PostedFile.FileName.ToString();
string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=Excel 8.0;";
OleDbConnection oleconn = new OleDbConnection(str);
OleDbCommand olecmd = new OleDbCommand("select * from [sheet1$]", oleconn);
oleconn.Open();
OleDbDataReader olereader = olecmd.ExecuteReader();
SqlConnection conn = new SqlConnection("server=.;database=Northwind;Integrated Security=SSPI");
conn.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from shippers",conn);
DataSet ds = new DataSet();
ada.Fill(ds,"shippers");
while (olereader.Read())
{
DataRow datarow = ds.Tables["shippers"].NewRow();
datarow["CompanyName"]=olereader.GetValue(1).ToString();
datarow["Phone"]=olereader.GetValue(2).ToString();
ds.Tables["shippers"].Rows.Add(datarow);
}
olereader.Close();
oleconn.Dispose();
oleconn.Close();
SqlCommand cmd = new SqlCommand("insert into shippers(CompanyName,Phone) values (@name,@phone)",conn);
cmd.Parameters.Add("@name",SqlDbType.NVarChar,20,"CompanyName");
cmd.Parameters.Add("@phone",SqlDbType.NVarChar,20,"Phone");
ada.InsertCommand = cmd;
ada.Update(ds,"shippers");
ada.Dispose();
conn.Dispose();
conn.Close();