示例#1
0
 /// <summary>
 /// Imports the file.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="db">The db.</param>
 /// <param name="file">The file.</param>
 public void ImportFile(CsvSettings settings, Database db, string file)
 {
     using (DataTable tbl = this.LoadTable(settings, file))
     {
         string sql = this.CreateInsertSQL(settings.Table);
         foreach (DataRow row in tbl.Rows)
         {
             using (IDbCommand cmd = db.CreateCommand(sql))
             {
                 foreach (Column col in this.Columns)
                 {
                     if (col.Enabled && !col.Autoincrement)
                     {
                         cmd.Parameters.Add(db.CreateParameter(col.Name, col.SystemType, row[col.Name]));
                     }
                 }
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
示例#2
0
 /// <summary>
 /// Creates the table.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="db">The database.</param>
 public void CreateTable(CsvSettings settings, Database db)
 {
     using (IDbCommand cmd = db.CreateCommand("select count(*) from sys.objects where type='U' and name=@name"))
     {
         cmd.Parameters.Add(db.CreateParameter("name", DbType.String, settings.Table));
         if (Convert.ToInt32(cmd.ExecuteScalar()) > 0)
         {
             using (IDbCommand cmdDrop = db.CreateCommand(string.Format("drop table {0}", settings.Table)))
             {
                 cmdDrop.ExecuteNonQuery();
             }
         }
     }
     string sql = this.CreateTableSQL(settings.Table);
     using (IDbCommand cmd = db.CreateCommand(sql))
     {
         cmd.ExecuteNonQuery();
     }
 }