singlesspot.blogg.se

Sqlpro load csv file to database
Sqlpro load csv file to database








sqlpro load csv file to database

The code would look like so: var dataReader = new CsvDataReader("pathToYourCsv", I wrote a package that I think could be of interest in cases such as yours. You can avoid that by using SqlBulkCopy class and an implementation of IDataReader interface. You may be risking an out of memory exception on the client side (your file processing server in this case) or, worse still, on SQL Server side. Unless you're sure that your files will never be massive, you should avoid loading the whole batch into memory and sending it all at once to SQL Server as is the case with the DataTable approach and (I think) your accepted answer. I know this is an old question, but for whoever may be interested. Return String.Format("INSERT INTO TF (IdProduit, Mois, Reel, Budget ) " + " VALUES ( '' ) ", obj.IdProduit, obj.Mois,obj.Reel, obj.Budget ) Protected string GetInsertSqlCust(object record) ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Données enregistrées avec succès !')", true) TBFtable res = CommonEngine.ReadFile(typeof(TBFtable), excelPath) as TBFtable Storage.InsertSqlCallback = new InsertSqlHandler(GetInsertSqlCust) SqlServerStorage storage = new SqlServerStorage(typeof(TBFtable),) String excelPath = Server.MapPath("~/Files/") + Path.GetFileName() Protected void UploadF(object sender, EventArgs e) net library called Filehelpers.Īnd here's the code behind : |-|-|-|-|-|-|-|-Īll the other columns should either be null or automatically calculated. On the other hand, my SQL Server table looks like this : |IdProduit|Mois|Reel|Budget|ReelPreviousMois|VarReelBudget|VarReelPrvM|. IdProduit is a string, Mois is a date, Reel and Budget are floats. Here is the canvas of my CSV file : 4 columns : IdProduit,Mois,Reel,Budget PS : TF has more columns than what the CSV file : some of the columns are computed and should be calculated automatically after each insert. SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock) StreamReader sr = new StreamReader(excelPath) SqlConnection con = new Source=SAMSUNG-PC\SQLEXPRESS Initial Catalog=TMPA Persist Security Info=True") string excelPath = Server.MapPath("~/Files/") + Path.GetFileName() One of the features of my web app is to upload CSV files, and import the data into a table (called TF) in my database (called TMPA).










Sqlpro load csv file to database