odbc实现导入导出的统一接口

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
File.Delete(PathNew + "\\schema.ini");
CreateConnString(tablename);
using (OdbcConnection conn = new OdbcConnection(strConnString.Trim()))
{
if (srcTable.Rows[j][i] != DBNull.Value)
{
if (i == 0)
s = s + "'" + srcTable.Rows[j][i].ToString() + "'";
private static string newtablename; //创建新表名称
private static string strConnString; //连接字符串
private static bool FileCheck(string filename)
//}
//else
//{
s = s + ",[" + srcTable.Columns[i].ColumnName + "] TEXT";
{
private static string FileNew = null; //文件名
private static string PathNew = null; //文件路径
private static byte FileType = 0; //导出文件类型 1-xls 2-xlsb 3-txt或csv
{
if ((filename == "") || (filename == null) || (filename == "") || (filename == null) || (filename == "") || (filename == null))
{
}
else
{
strConnString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + PathNew
+ ";Extensions=asc,csv,tab,txt;Persist Security Info=False;;";
sw.Start();
using (DataSet srcData = BaseDbManager.GetDataSet("SELECT * FROM " + tablename))
{
if (srcData == null)
{
BaseEvent.BaseEvent.AddMsg(EventTypes.BF6500ImExportError.ToString(), "No export data");
return false;
{
FileNew = System.IO.Path.GetFileName(filename);
PathNew = System.IO.Path.GetDirectoryName(filename);
if (temp == ".xls")
strConnString = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + PathNew + "\\"
+ FileNew + "; DriverID=790;;";//FIL=Excel 12.0;";//CREATE_DB=" + PathNew + "\\" + FileNew;
for (int j = 0; j < srcTable.Rows.Count; j++)
{
Байду номын сангаас s = "";
for (int i = 0; i < srcTable.Columns.Count; i++)
0
Connectez-vous pour voter
小弟刚刚接触c#两个月,最近做项目中的配置导入导出功能,研究了几天,找了很多资料写了一个ODBC的接口,贴出来希望大家多给写意见。
namespace BaseDatabase
{
public class ExportAndImport
{
//if (numlx.Contains(srcTable.Columns[i].DataType.ToString()))
//{
// s = s + ",[" + srcTable.Columns[i].ColumnName + "] NUMBER";
}
return false;
}
private static void CreateConnString(string tablename)
{
if (FileType == 1)
{
OdbcCommand cmd1 = new OdbcCommand(s, conn);
cmd1.ExecuteNonQuery();
//插入数据
f = "insert into " + newtablename + "(" + f.Substring(1) + ") values(";
}
//创建表
DataTable srcTable = srcData.Tables[0];
for (int i = 0; i < srcTable.Columns.Count; i++)
if (File.Exists(filename))
File.Delete(filename);
if (File.Exists(PathNew + "\\schema.ini")) //如果细化的话可以把schema.ini中的指定文件配置删除掉,否则可能会影响其它文件
newtablename = "[" + FileNew + "]";
}
}
/*
public static bool SqlExportFile(string filename, string tablename)
newtablename = tablename;
}
else if (FileType == 3)
{
strConnString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" +
{
string s = "";
string f = "";
conn.Open();
Stopwatch sw = new Stopwatch(); //测试运行效率
return false;
}
//获得文件扩展名
string temp = System.IO.Path.GetExtension(filename);
if (temp == ".xls" || temp == ".txt" || temp == ".csv" || temp == ".xlsb")
odbc实现导入导出的统一接口
Poser une question
jeudi 7 octobre 2010 02:40
Avatar de lioncheng
lioncheng
0 Points
A du code
Connectez-vous pour voter
FileType = 1;
else if (temp == ".xlsb")
FileType = 3;
else
FileType = 2;
return true;
public static bool SqlExportFile(string filename, string tablename)
{
try
{
if (FileCheck(filename))
{
//}
f = f + ",[" + srcTable.Columns[i].ColumnName + "]";
}
s = @"CREATE TABLE " + newtablename + " (" + s.Substring(1) + ")";
"DriverID=1046;FIRSTROWHASNAMES=1;Readonly=False;DBQ="
+ PathNew + "\\" + FileNew;
newtablename = tablename;
Description:把数据库中单个表导出,
Input:filename 预导出文件名(含路径)
tablename 数据库中的表明。
Return:
false 失败
ture 成功
*/
相关文档
最新文档