如何导入excel文件时候update 数据库相关字段

forwardchen 2006-09-14 11:28:57
如题
...全文
203 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
forwardchen 2006-09-18
  • 打赏
  • 举报
回复
能不能用sql语句直接搞定啊
levin9 2006-09-14
  • 打赏
  • 举报
回复
剛做好的
public static string imp_currency(int yearly,int monthly,System.Web.UI.HtmlControls.HtmlInputFile FileUp)
{
string result="",currency="";
int i=0,times=1,ErrorType=0;
float rate=0;
System.Text.StringBuilder sb=new System.Text.StringBuilder();
System.Text.StringBuilder logs=new System.Text.StringBuilder();
Components.FileUpModem fileMod=new FileUpModem();
DataSet ds=new DataSet();
fileMod=Components.UpFile.UploadFile(FileUp,"FileUpLoad");
string filePath=fileMod.CurrentPath;
ds=Components.Staff.ExcelToDs(filePath);
System.Collections.Hashtable hs_Currency=imp_Currency();
System.Collections.Hashtable hs_set_currency=set_Currency(yearly,monthly);
for ( i=0;i<ds.Tables[0].Rows.Count;i++)
{
try
{
rate=float.Parse(ds.Tables[0].Rows[i][3].ToString());
}
catch
{
ErrorType=1;
}
currency=ds.Tables[0].Rows[i][2].ToString().Trim();
string currencyCH = (string)hs_Currency[currency];
if (currencyCH==null)
{
ErrorType=2;
}

if (ErrorType==0)
{
string tmp2=(string)hs_set_currency[currency];
if (tmp2==null)
{
sb.Append(" insert into pubCurrency (yearly,monthly,Currency,CurrencyCH,Rate) values ("
+ yearly + "," + monthly + ",'" + currency + "','" + currencyCH + "'," + rate +") ; ");
}
else
{
sb.Append(" update pubCurrency set Rate=" + rate + "where yearly=" + yearly + " and monthly=" + monthly + " and currency='" + currency + "' ;");
}
times ++;
}
else
{
//logs.Append(addLogs(ds.Tables[0].Rows[i],ErrorType));
logs.Append("</br>");
}
if (times%10==0)
{
Components.db.SqlBase.ExecSql(sb);
sb.Remove(0,sb.Length);
}
}
if (i>0) Components.db.SqlBase.ExecSql(sb);
return result;
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧