html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

ASP.NETR把Excel导入SQL数据库的自定义类_.NET教程_编程技术

[ ] 已经帮助:人解决问题

ASP.NETR把Excel导入SQL数据库的自定义类

以下是引用片段:
public class SaveToSql
{
  public string strNewCodeId = string.Empty;
  public string strNewCode = string.Empty;
  public string strNewDes = string.Empty;
  public string strOldCodeId = string.Empty;
  public string strOldCode = string.Empty;
  public string strOldDes = string.Empty;
  public string Server = string.Empty;
  public string DataBase = string.Empty;
  public string Uid = string.Empty;
  public string Pwd = string.Empty ;
  private string TableName = string.Empty;
  /// <summary>
  /// 目的表的名称
  /// </summary>
  public string TableNames
  {
  get{return TableName;}
  set{TableName=value;}
  }
  public SaveToSql()
  {
  }
  /// <summary>
  /// 保存数据
  /// </summary>
  public  void Save()
  {
  string strConPath = string.Format("server={0};database={1};uid={2};pwd={3}",this.Server,this.DataBase,this.Uid,this.Pwd);
  SqlConnection con1 = new SqlConnection(strConPath);
  con1.Open();
  SqlCommand com1 = new SqlCommand();
  com1.CommandText = "Insert into "+TableName+"(newCodeId,newCode,newDes,oldCodeId,oldCode,oldDes) Values(’"+strNewCodeId+"’,’"+strNewCode+"’,’"+strNewDes+"’,’"+strOldCodeId+"’,’"+strOldCode+"’,’"+strOldDes+"’)";
  com1.Connection=con1;
  com1.ExecuteNonQuery();
  con1.Dispose();
  }
}

VHcHTML5中文学习网 - HTML5先行者学习网
VHcHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助