数据表选择所有行

时间:2016-09-14 19:57:22

标签: sql linq datatable

我想使用select * from datatable将特定列插入到表中。但是它给了我一个数组..有什么方法可以让Insert工作。

all I want to do is 
Insert into table1 (id,name,status) select * from datatable



query += "Insert into " + tableName.ToLower() + "";

query += "(";
for (int i = 0; i < dt.Columns.Count; i++)
{
    if (i != dt.Columns.Count - 1)
        query += dt.Columns[i].ColumnName.ToLower() + ",";
    else
        query += dt.Columns[i].ColumnName.ToLower();
}
query += ")";


DataRow[] result = dt.Select();

query += "select * from " + result

1 个答案:

答案 0 :(得分:0)

您不能同时使用两个sql语句,就像您必须将它们分成两个不同的对象或变量一样(当您以分号结束时,有时允许它;但在您的情况下不是这样) 尝试获取行中的每个单元格值

LastRowA = Range("A" & Rows.Count).End(xlUp).Row
LastRowB = Range("B" & Rows.Count).End(xlUp).Row

'Fill down (will auto-increment)
Range("A" & LastRowA).AutoFill Destination:=Range("A" & LastRowA & ":A" & LastRowB)

'EDIT: fill with same fixed value...
Range("A" & (LastRowA+1) & ":A" & LastRowB).Value = Range("A" & LastRowA).Value

}

相关问题