将DataTable的TableName属性设置为数据库中表的名称,然后调用该方法
public static string ExecuteInsert(DataTable dt)
{
string sql="";
string fieldStr="";
string valueStr="";
int i=0;
try
{
for(i=0;i
{
fieldStr += dt.Columns[i].ColumnName + ",";
}
fieldStr = fieldStr.Substring(0,fieldStr.Length-1);
for(i=0;i
{
sql = "insert into {0}({1}) values({2})";
valueStr ="";
for(int j=0;j
{
switch(System.Type.GetTypeCode(dt.Rows[i][j].GetType()))
{
case System.TypeCode.Byte:
case System.TypeCode.Char:
case System.TypeCode.Decimal:
case System.TypeCode.Double:
case System.TypeCode.Int16:
case Syste