This is just an example how I would do this (which means it possibly is bug ridden and wrong...)
CSV File:
Column:ColumnType:size:n, Column:Type:size:n, Column:Type:size:y
C1Data, C2Data, C3Data
Pseudo Code:
StringBuilder sql = new StringBuilder();
sb.append("CREATE TABLE " + someTableName+ "(" + Environment.NewLine);
for(string s in csvlines) {
if(first_line) {
// pull apart our columns
string[] cols = s.Split(new char[] { ',' });
// iterate over the list of columns
for(string col in cols) {
// pull apart the column name, type, size and nullable flag
string[] ci = col.Split(new char[] { ':' });
// add our column name and add the datatype
sb.Append("[" + ci[0] + "]" + " [" + ci[1] + "] ");
// only put a size if value greater than 0
if(ci[2] != "0") {
sb.Append("(" + ci[2] + ") ");
}
// put our NULLABLE flag on NULL columns only
if(ci[3] == "y") {
sb.Append("NULL," + Environment.NewLine);
} else {
sb.Append("NOT NULL," + Environment.NewLine);
}
}
// remember the above has a bug where the last column has a rouge ,
sb.Append(")");
} else {
// create our insert statement and insert as appropriate
}
}
May be disgusting, maybe dirty, may just do what you require!