码迷,mamicode.com
首页 > 其他好文 > 详细

自动创建orcl表

时间:2015-05-26 22:57:18      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Holworth.Utility;

namespace ConsoleApplication22
{
public enum OrclType
{
字段 = 0,
类型 = 1,
长度 = 2
};

class Program
{
/// <summary>
/// dic字典用于存储特征类型在Excel中的列索引,后续得到使用子段列对应的值是便可通过此字典进行抽象
/// </summary>
static Dictionary<string, int> dic = new Dictionary<string, int>();
static void Main(string[] args)
{
string path = @"d:\rskbook.xls";
string fileName = @"Sheet1$";
DataTable dt = ExcelUtil.GetExcelSheetContent(path, fileName);

DataRow dr = dt.Rows[0];
for (int i = 0; i < dt.Columns.Count; i++)
{
string columnName = dr[i].ToString();
if (columnName == OrclType.字段.ToString())
{
dic.Add(columnName, i);
}
if (columnName == OrclType.类型.ToString())
{
dic.Add(columnName, i);
}
if (columnName == OrclType.长度.ToString())
{
dic.Add(columnName, i);
}
}

StringBuilder sb = new StringBuilder();
sb.AppendFormat(string.Format("create table tab1\r\n("));

for (int i = 1; i < dt.Rows.Count; i++)
{
DataRow row = dt.Rows[i];
int FiledIndex = getColIndex(OrclType.字段);
int TypeIndex = getColIndex(OrclType.类型);
string LengthStr = "";
if (row[TypeIndex].ToString() != "date" && row[getColIndex(OrclType.长度)].ToString().Trim() != "")
LengthStr += "(" + row[getColIndex(OrclType.长度)] + ")";
if (i != dt.Rows.Count - 1)
sb.AppendFormat(string.Format("{0} {1},", row[FiledIndex], row[TypeIndex].ToString() + LengthStr));
else
{
sb.AppendFormat(string.Format("{0} {1}", row[FiledIndex], row[TypeIndex].ToString() + LengthStr));
}
sb.Append("\r\n");
}
sb.AppendFormat(@")");
Console.WriteLine(sb.ToString());
Console.ReadKey();
}

public static int getColIndex(OrclType col)
{
return dic[col.ToString()];
return 0;
}
}
}

自动创建orcl表

标签:

原文地址:http://www.cnblogs.com/kexb/p/4531806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!