private DataSet GetExcel(string Path)
{
OleDbConnection objConn=null;
DataSet data=new DataSet();
try
{
string strConn= "Provider=Microsoft.Jet.OleDb.4.0;" + "data source="+Path+ ";Extended Properties=Excel 5.0;";
objConn=new OleDbConnection(strConn);
objConn.Open();
DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null);
string tableName=schemaTable.Rows[0][2].ToString().Trim();
string strSql= "Select * From ["+tableName+"]";
OleDbCommand objCmd=new OleDbCommand(strSql, objConn);
OleDbDataAdapter sqlada=new OleDbDataAdapter();
sqlada.SelectCommand=objCmd;
sqlada.Fill(data,"BuyPrice");
objConn.Close();
}
catch
{
objConn.Close();
throw;
}
return data;
} 先将EXCEL 文件(拷贝到服务器的)中的数据转换成DATASET
再每条转换数据格式再插数据库这里估计有1000多条和很少
见下面的存储过程:
CREATE PROCEDURE DataIn_Products_Update
AS
SET XACT_ABORT ON
begin transaction
update CMRC_Products
set Categoryid=b.realid
from
(
select c.Categoryid realid,t.categoryid faleid from
CMRC_Categories_Temp t,CMRC_Categories c
where t.CategoryName=c.CategoryName
)b
where categoryid=b.faleid
insert into CMRC_Products_New select
Convert(int,CategoryID),ModelNumber,ModelName,Spec,Unit,UnitCost,PackUnit,Description,CostPrice,FactoryPrice,SuggestPrice,ExecuteDateStart,ExecuteDateEnd,BlankOutTag,BarCode,Re,Stocks,UpperLimitStocks,LowerLimitStocks,AttributeID,LockIn,MaySendOut
from CMRC_Products
delete from CMRC_Productslist
insert into CMRC_Productslist
select c.CustomerId,p1.ProductId,p1.unitcost,p1.unitcost,p1.unitcost,
getdate(),dateadd(year,1,getdate()),
'1',
p1.re,
'0.17','1.0',unitcost*0.83
from CMRC_Customers c cross join
(select p.ProductId,p.unitcost,
p.re from CMRC_Products p where p.BlankOutTag='1' ) p1
if @@error=0
commit tran
else
rollback tran
GO
这个存储过程处理的书记就上几十万条了
我很担心服务器被脱跨
{
OleDbConnection objConn=null;
DataSet data=new DataSet();
try
{
string strConn= "Provider=Microsoft.Jet.OleDb.4.0;" + "data source="+Path+ ";Extended Properties=Excel 5.0;";
objConn=new OleDbConnection(strConn);
objConn.Open();
DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,null);
string tableName=schemaTable.Rows[0][2].ToString().Trim();
string strSql= "Select * From ["+tableName+"]";
OleDbCommand objCmd=new OleDbCommand(strSql, objConn);
OleDbDataAdapter sqlada=new OleDbDataAdapter();
sqlada.SelectCommand=objCmd;
sqlada.Fill(data,"BuyPrice");
objConn.Close();
}
catch
{
objConn.Close();
throw;
}
return data;
} 先将EXCEL 文件(拷贝到服务器的)中的数据转换成DATASET
再每条转换数据格式再插数据库这里估计有1000多条和很少
见下面的存储过程:
CREATE PROCEDURE DataIn_Products_Update
AS
SET XACT_ABORT ON
begin transaction
update CMRC_Products
set Categoryid=b.realid
from
(
select c.Categoryid realid,t.categoryid faleid from
CMRC_Categories_Temp t,CMRC_Categories c
where t.CategoryName=c.CategoryName
)b
where categoryid=b.faleid
insert into CMRC_Products_New select
Convert(int,CategoryID),ModelNumber,ModelName,Spec,Unit,UnitCost,PackUnit,Description,CostPrice,FactoryPrice,SuggestPrice,ExecuteDateStart,ExecuteDateEnd,BlankOutTag,BarCode,Re,Stocks,UpperLimitStocks,LowerLimitStocks,AttributeID,LockIn,MaySendOut
from CMRC_Products
delete from CMRC_Productslist
insert into CMRC_Productslist
select c.CustomerId,p1.ProductId,p1.unitcost,p1.unitcost,p1.unitcost,
getdate(),dateadd(year,1,getdate()),
'1',
p1.re,
'0.17','1.0',unitcost*0.83
from CMRC_Customers c cross join
(select p.ProductId,p.unitcost,
p.re from CMRC_Products p where p.BlankOutTag='1' ) p1
if @@error=0
commit tran
else
rollback tran
GO
这个存储过程处理的书记就上几十万条了
我很担心服务器被脱跨
解决方案 »
- 如何让float型小数个位显示0
- 求:一个较为复杂的SQL语句?两个表的混合查询.....
- in 的困惑
- 寻求一对多的较好解决方案,高手帮忙
- 条件可选的两个表能连接起来查询吗?
- 查找问题
- 跪求:字段由float(小数点后6位)型修改为money型(小数点后4位)导致数据丢失,如何恢复?
- 我有一个SQL Server6.5的数据库备份文件(*.dat),有没有人知道我怎样才能将这个数据库还原到SQL Server2000中
- 如何用一条SQL语句或存储过程实现以下查询?
- vfp:一个关于文本框的简单问题!
- 这个存储过程错在哪啊,请高手帮忙啊
- 通过自己的程序来操作数据库恢复时候遇到的 问题 sqldmo 开发语言vb.net
如果EXCEL数据上万条 后面那个存储过程就得处理上百万或者上千万的航速据量