public void Insert(List <object[]> data, string tableName) { DataTable dt = null; using (Conn = new SqlConnection(ConnStr)) { Conn.Open(); string query = string.Format(@"select top 0 * from {0}", tableName); using (SqlCommand command = new SqlCommand(query, Conn)) { using (SqlDataReader dr = command.ExecuteReader()) { dt = LibsData.GetDataTable(dr, data); } } // data to dataReader using (SqlBulkCopy bulkCopy = new SqlBulkCopy(Conn)) { bulkCopy.DestinationTableName = tableName; bulkCopy.WriteToServer(dt); } Conn.Close(); } }
public void Insert(List <object[]> data, string tableName) { Conn = new MySqlConnection(ConnStr); Conn.Open(); string query = string.Format(@"select * from {0} limit 0", tableName); MySqlCommand command = new MySqlCommand(query, Conn); IDataReader rd = command.ExecuteReader(); DataTable dt = LibsData.GetDataTable(rd, data); Conn.Close(); string filePath = GetAvailableFilePath(); System.IO.File.Delete(filePath); LibFile.WriteTextFileWithHeader(filePath, dt, false); InsertFromTextFile(filePath, tableName); System.IO.File.Delete(filePath); }