protected void SqlBulkCopyData(DataTable dt)
{
//使用SqlBulkCopy把内存表DataTable里的数据插入答卷数据表
SqlBulkCopy bcp = new SqlBulkCopy(connectionString);
//指定目标数据库的表名
bcp.DestinationTableName = "tAnswer";
//建立数据源表字段和目标表中的列之间的映射
SqlBulkCopyColumnMapping MapUserID = new SqlBulkCopyColumnMapping();
MapUserID.DestinationColumn = "fUserID";
MapUserID.SourceColumn = "UserID";
bcp.ColumnMappings.Add(MapUserID);
SqlBulkCopyColumnMapping MapQID = new SqlBulkCopyColumnMapping();
MapQID.DestinationColumn = "fQuestionID";
MapQID.SourceColumn = "QuestionID";
bcp.ColumnMappings.Add(MapQID);
SqlBulkCopyColumnMapping MapAnswer = new SqlBulkCopyColumnMapping();
MapAnswer.DestinationColumn = "fAnswer";
MapAnswer.SourceColumn = "Answer";
bcp.ColumnMappings.Add(MapAnswer);
//写入数据库表
bcp.WriteToServer(dt);
bcp.Close();
}