本文整理汇总了C#中System.Data.DataSet.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.DataSet.Dispose方法的具体用法?C# System.Data.DataSet.Dispose怎么用?C# System.Data.DataSet.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataSet
的用法示例。
在下文中一共展示了System.Data.DataSet.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DataTableToExcel
/// <summary>
/// 导出Excel,以旧列名-新列名词典为标头
/// </summary>
/// <param name="dt"></param>
/// <param name="dicCoumnNameMapping"></param>
public static void DataTableToExcel(System.Data.DataTable dt, Dictionary<string, string> dicCoumnNameMapping, string fileName)
{
ExcelHandler eh = new ExcelHandler();
SheetExcelForm frm = new SheetExcelForm();
eh.ProcessHandler = frm.AddProcess;
eh.ProcessErrorHandler = new Action<string>((msg) =>
{
MessageBox.Show(msg);
});
try
{
frm.Show();
Delay(20);
var ds = new System.Data.DataSet();
ds.Tables.Add(dt);
eh.DataSet2Excel(ds, dicCoumnNameMapping, fileName);
ds.Tables.Remove(dt);
ds.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("导出Excel错误:" + ex.Message);
}
finally
{
Delay(20);
frm.Close();
}
}
示例2: DataTableToExcelWithTemplate
/// <summary>
/// 按照模板导出
/// </summary>
/// <param name="dt">要导出的datatable</param>
/// <param name="templateFile">要导出的excel模板文件</param>
/// <param name="saveFile">要保存的文件名,可以为空</param>
public void DataTableToExcelWithTemplate(System.Data.DataTable dt, string templateFile, string saveFile)
{
ExcelHandler eh = new ExcelHandler();
try
{
string exportDir = "~/ExcelFile/";//注意:该文件夹您须事先在服务器上建好才行
if (System.IO.Directory.Exists(GetPhysicalPath(exportDir)) == false)
{
System.IO.Directory.CreateDirectory(GetPhysicalPath(exportDir));
}
if (string.IsNullOrEmpty(saveFile)) saveFile = DateTime.Now.ToString("yyyyMMddHHmmssfff_") + ".xls";
//设置文件在服务器上的路径
string physicalFileName = GetPhysicalPath(System.IO.Path.Combine(exportDir, saveFile));
eh.ProcessErrorHandler = this.ErrorMessageHandler;
var ds = new System.Data.DataSet();
ds.Tables.Add(dt);
string tmpFile = eh.ExportWithTemplate(dt, templateFile, physicalFileName, false);
ds.Tables.Remove(dt);
ds.Dispose();
//==============返回客户端
ResponeToClient(physicalFileName, saveFile);
try
{
if (!string.IsNullOrEmpty(tmpFile))
{
System.IO.FileInfo fi = new System.IO.FileInfo(tmpFile);
if (fi.Exists)
{
fi.Attributes = System.IO.FileAttributes.Normal;
System.IO.File.Delete(tmpFile);
}
}
}
catch (Exception ex)
{
AddMessage(ex.Message);
}
}
catch (Exception ex)
{
if (this.ErrorMessageHandler != null) ErrorMessageHandler("导出过程中出错," + ex.Message);
if (ErrorHandler != null) ErrorHandler(ex);
GC.Collect();
}
}
示例3: Report
public ActionResult Report(string filter)
{
//if (report.Acao == RP.Report.TipoAcao.Agendar)
//{
// return RP.Report.Generic.Json(report);
//}
int idUsuario = _idUsuario > 0 ? _idUsuario : Convert.ToInt32(Request["idUsuario"]);
Dictionary<string, System.Data.DataSet> listData = new Dictionary<string, System.Data.DataSet>();
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.DataTable table = new System.Data.DataTable("table");
System.Data.DataRow row;
string titulo;
BLL.AreaBLL areaBLL;
try
{
using (var db = new Context())
{
areaBLL = new BLL.AreaBLL(db, idUsuario);
var areas = areaBLL.Search(filter);
table.Columns.Add(new System.Data.DataColumn("idarea", System.Type.GetType("System.Int32")));
table.Columns.Add(new System.Data.DataColumn("nmarea", System.Type.GetType("System.String")));
table.Columns.Add(new System.Data.DataColumn("dsarea", System.Type.GetType("System.String")));
table.Columns.Add(new System.Data.DataColumn("flusaurl", System.Type.GetType("System.String")));
foreach (Area area in areas)
{
row = table.NewRow();
row["idarea"] = area.idArea;
row["nmarea"] = area.nmArea;
row["dsarea"] = area.dsArea;
row["flusaurl"] = area.flUsaURL;
table.Rows.Add(row);
}
ds.Tables.Add(table);
listData.Add("subentidade.rpt", RP.Sistema.BLL.EntidadeBLL.getDtSetEntidade(db));
listData.Add("table", ds);
}
titulo = string.Format("<center>Relação de Áreas{0}</center>", !string.IsNullOrEmpty(filter) ? ("</br>Nome contendo: " + filter) : "");
//return View();
return RP.Report.Generic.Report(new RP.Report.Generic.GenericData
{
exportTO = RP.Report.Generic.stringTOExportFormatType("PDF"),
fileRPT = "relArea.rpt",
listData = listData,
parameters = new Dictionary<string, object> { { "titulo", titulo } },
});
}
catch (RP.Report.Exception rex)
{
RP.Util.Entity.ErroLog.Add(rex, Session.SessionID, idUsuario);
return RedirectToAction("Index", "Erro");
}
catch (Exception ex)
{
RP.Util.Entity.ErroLog.Add(ex, Session.SessionID, idUsuario);
return RedirectToAction("Index", "Erro");
}
finally
{
ds.Dispose();
}
}
示例4: writeXML
/// <summary>
/// дXML�ĵ�
/// </summary>
/// <param name="name">���ݿ������������</param>
/// <param name="con_str">���ݿ������Դ��Ϣ</param>
public void writeXML(string name , ConfigStruct con_str)
{
try
{
//����һ��dataset
System.Data.DataSet ds = new System.Data.DataSet("Autoconfig");
//�ж��Ƿ����config.xml�ļ�,������ڴӸ��ļ��ж�ȡ���ݵ�dataset
if(System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName))
{
ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName);
}
//�ж��Ƿ���ڸñ�,���������ɾ���ñ�
if(ds.Tables.IndexOf(name.ToUpper()) != -1 )
{
ds.Tables.Remove(name.ToUpper());
}
//����һ��datatable
System.Data.DataTable dt = new System.Data.DataTable(name.ToUpper());
//Ϊ�¶���ı�������
dt.Columns.Add("key");
dt.Columns.Add("value");
SymmetricMethod sm = new SymmetricMethod();
//���Ӽ�¼���¶���ı���
dt.Rows.Add(new object[2]{ sm.Encrypto( str_HA ), sm.Encrypto( con_str.hostAddress)});
dt.Rows.Add(new object[2]{ sm.Encrypto( str_UN ), sm.Encrypto( con_str.userName)});
dt.Rows.Add(new object[2]{ sm.Encrypto( str_PWD ), sm.Encrypto( con_str.password)});
dt.Rows.Add(new object[2]{ sm.Encrypto( str_DBN ), sm.Encrypto( con_str.DBName)});
//�������ӵ�������µ�dataset��
ds.Tables.Add(dt);
//д��xml�ĵ�
ds.WriteXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName);
//�ͷ�datatable �� dataset
dt.Dispose();
ds.Dispose();
}
catch(Exception exp)
{
//System.Windows.Forms.MessageBox.Show(exp.Message);
throw exp;
}
}
示例5: readXML
/// <summary>
/// ��XML�ĵ�
/// </summary>
/// <param name="name">Ҫȡ�������ļ��е�ָ������Դ������,��:��ϵͳ "oldsystem" </param>
public ConfigStruct readXML(string name)
{
try
{
//�����µĽṹ����
ConfigStruct cfg = new ConfigStruct();
//����һ���µ�dataset
System.Data.DataSet ds = new System.Data.DataSet();
//�ж��ļ��Ƿ����,��������ʾ������һ���յĽṹ����
if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\"+_FileName))
{
//����������ȡconfig.xml�ļ�������
ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName);
}
else
{
// System.Windows.Forms.MessageBox.Show("config.xml�ļ�������!" , "����",
// System.Windows.Forms.MessageBoxButtons.OK ,
// System.Windows.Forms.MessageBoxIcon.Warning);
return new ConfigStruct();
}
//�жϱ��Ƿ����,��������ʾ������һ���յĽṹ����
if (ds.Tables.IndexOf(name.ToUpper())== -1 )
{
// System.Windows.Forms.MessageBox.Show("��config.xml�в����ҵ���ص�����Դ��������Ϣ!" , "����",
// System.Windows.Forms.MessageBoxButtons.OK ,
// System.Windows.Forms.MessageBoxIcon.Warning);
return new ConfigStruct();
}
SymmetricMethod sm = new SymmetricMethod();
// cfg.hostAddress = "CIT16-PC";
//cfg.userName ="sa";
//cfg.password ="111111";
//cfg.DBName = "AutoUpDateData";
//������ȡ��ֵ
cfg.hostAddress = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_HA) + "'")[0]["value"].ToString());
cfg.userName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_UN) + "'")[0]["value"].ToString());
cfg.password = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_PWD) + "'")[0]["value"].ToString());
cfg.DBName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_DBN) + "'")[0]["value"].ToString());
ds.Dispose();
return cfg;
}
catch//(Exception exp)
{
//System.Windows.Forms.MessageBox.Show(exp.Message);
return new ConfigStruct();
}
}
示例6: Report
public ActionResult Report(string filter)
{
//if (report.Acao == RP.Report.TipoAcao.Agendar)
//{
// return RP.Report.Generic.Json(report);
//}
int idUsuario = _idUsuario > 0 ? _idUsuario : Convert.ToInt32(Request["idUsuario"]);
Dictionary<string, System.Data.DataSet> listData = new Dictionary<string, System.Data.DataSet>();
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.DataTable table = new System.Data.DataTable("table");
System.Data.DataRow row;
string titulo;
BLL.MenuBLL menuBLL;
BLL.AcaoBLL acaoBLL;
try
{
using (var db = new Context())
{
menuBLL = new BLL.MenuBLL(db, idUsuario);
acaoBLL = new BLL.AcaoBLL(db, idUsuario);
var menus = menuBLL.Search(filter);
table.Columns.Add(new System.Data.DataColumn("idmenu", System.Type.GetType("System.Int32")));
table.Columns.Add(new System.Data.DataColumn("nmmenu", System.Type.GetType("System.String")));
table.Columns.Add(new System.Data.DataColumn("nmacao", System.Type.GetType("System.String")));
table.Columns.Add(new System.Data.DataColumn("dsacao", System.Type.GetType("System.String")));
table.Columns.Add(new System.Data.DataColumn("acaomenu", System.Type.GetType("System.String")));
foreach (Menu menu in menus)
{
var acoes = acaoBLL.Find(e => e.idMenu == menu.idMenu).ToList();
if (acoes.Count() > 0)
{
foreach (Acao acao in acoes)
{
row = table.NewRow();
row["idmenu"] = menu.idMenu;
row["nmmenu"] = menu.nmMenu;
row["nmacao"] = acao.nmAcao;
row["dsacao"] = acao.dsAcao;
row["acaomenu"] = acao.nmMenu;
table.Rows.Add(row);
}
}
else
{
row = table.NewRow();
row["idmenu"] = menu.idMenu;
row["nmmenu"] = menu.nmMenu;
table.Rows.Add(row);
}
}
ds.Tables.Add(table);
listData.Add("subentidade.rpt", RP.Sistema.BLL.EntidadeBLL.getDtSetEntidade(db));
listData.Add("table", ds);
}
titulo = string.Format("<center>Relação de Menus{0}</center>", !string.IsNullOrEmpty(filter) ? ("</br>Nome contendo: " + filter) : "");
return View();
//return RP.Report.Generic.Report(new RP.Report.Generic.GenericData
//{
// exportTO = RP.Report.Generic.stringTOExportFormatType("PDF"),
// fileRPT = "relModulo.rpt",
// listData = listData,
// parameters = new Dictionary<string, object> { { "titulo", titulo } },
//});
}
catch (RP.Report.Exception rex)
{
RP.Util.Entity.ErroLog.Add(rex, Session.SessionID, idUsuario);
return RedirectToAction("Index", "Erro");
}
catch (Exception ex)
{
RP.Util.Entity.ErroLog.Add(ex, Session.SessionID, idUsuario);
return RedirectToAction("Index", "Erro");
}
finally
{
ds.Dispose();
}
}
示例7: DataTableToExcle
public void DataTableToExcle(System.Data.DataTable dt, Dictionary<string, string> dicCoumnNameMapping, string fileName)
{
try
{
string exportDir = "~/ExcelFile/";//注意:该文件夹您须事先在服务器上建好才行
if (System.IO.Directory.Exists(GetPhysicalPath(exportDir)) == false)
{
System.IO.Directory.CreateDirectory(GetPhysicalPath(exportDir));
}
if (string.IsNullOrEmpty(fileName)) fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
//设置文件在服务器上的路径
string physicalFileName = GetPhysicalPath(System.IO.Path.Combine(exportDir, fileName));
ExcelHandler eh = new ExcelHandler();
eh.ProcessErrorHandler = this.ErrorMessageHandler;
var ds = new System.Data.DataSet();
ds.Tables.Add(dt);
eh.DataSet2Excel(ds, dicCoumnNameMapping, physicalFileName);
ds.Tables.Remove(dt);
ds.Dispose();
//==============返回客户端
ResponeToClient(physicalFileName, fileName);
}
catch (Exception ex)
{
if (this.ErrorMessageHandler != null) ErrorMessageHandler("导出过程中出错," + ex.Message);
if (ErrorHandler != null) ErrorHandler(ex);
GC.Collect();
}
}