C# - Import Data From CSV

Jul 14, 2010

this started out as a pretty simple task to import a customers data into our database. The script below loads all the data into memory and then allow manipulation after.

string ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="" + FileLoc + ""; Extended Properties="text;HDR=Yes;FMT=Delimited(,)"";
using (OleDbConnection conn = new OleDbConnection(ConString))
{
using (OleDbCommand cmd = new OleDbCommand("SELECT * FROM DataInput.csv", conn))
{
conn.Open();
using (OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
{
int RowNumber = 0;
while (dr.Read())
{
if(RowNumber==0)
{
for (int i = 0; i < dr.FieldCount; i++)
{
TitleData.Add(new CSVTitleData() {ColumnID = i,ColumnName = dr.GetValue(i).ToString()});
}
}
else
{
var DataToInsert = new List<CSVData>();
for (int i = 0; i < dr.FieldCount; i++)
{
if (i == 8)
{
var A = dr.GetValue(i);
Console.WriteLine(A.GetType().ToString() + " - " + i);
}
DataToInsert.Add(new CSVData(){ColumnID = i,Value = dr.GetValue(i).ToString()});
}
Content.Add(DataToInsert);
}
RowNumber++;
}
}
}
}
This works fine until there is data like
4950
4951
4952
4998
2024
4176
7025-1
RVAC010
RVAC011
4945
4946
4947
4948

Excel tries to be clever and reads each of the fields as an Int. Resulting int the ones with a letters in being read as DBNull. Now I've done some reading and there are lots of people with this question but no solid solution. One of the possible solutions is to create a Scheme.ini I wonder if someone can help me out with the exact format of that? Or perhaps there is an easier was of reading in the CSV?

View 3 Replies


Similar Messages:

Data Import Page Where Start The Import By Clicking A Button?

Apr 23, 2010

I have a data import page where I start the Import by clicking a button.Second by second I want to print in Web Page informations about record is being importing.

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="CurrentTimePanel" runat="server">
<ContentTemplate>
<asp:Label ID="CurrentTime" runat="server" Text="Now: " />
[code]...

View 5 Replies

Data Controls :: Import Excel With Parent Child Relationship Data To Database

Mar 26, 2016

I have an excel sheet which has several parent records/rows and every parent row/record has several child sub-records under it. I have a field called ID which is of the type String as it contains a mixture of characters and numbers and is common for both parent and child records. How do I store the parent and child records in separate database tables, retrieve them and display them in a nested gridview?

View 1 Replies

Forms Data Controls :: Import Data From Gridview To SQL Server Database?

Dec 2, 2010

I am developing a asp.net website..in the admin side..i have a gridview...i want to copy all the data in the gridview to a table in sql server 2005..

View 3 Replies

Forms Data Controls :: Import Data To Excel Sheet From Database?

Jul 2, 2010

i am binding a gridview through a query like select * from table, But i am not showing all fields in gridView. Only few fields i am showing in gridview. Now I want to import data to a excel sheet. i want to import data showing by gridview and also which is not showing by gridview. i meant all fields in database table should import to excel sheet.

View 1 Replies

Forms Data Controls :: Import Excel Sheet Data Into Dataset Or Gridview And Save To DB?

Mar 2, 2011

i am use this code for read excel file:

[Code]....

how to read special cells in excel and I save to DB.

for example: B4 and C4 is merged with named B4.how to read Data of this cell.

View 4 Replies

Forms Data Controls :: Import Excel Data To Gridview

Apr 15, 2010

Can anyone suggest a good Article which shows this operation.

View 4 Replies

Data Controls :: Import Excel Data To SQL Azure Database

Jul 31, 2013

I am making a form to import excel sheet from local computer to azure sql database easily.

I am using [URL] ... 

I have made The ID as :  Identity, Not Null.

As in my Excel sheet data the ID column is empty, as normally i used to integrate whole excel to sql db so it auto generate, but its waste of my time.

So I want to ask in order to make it successful in case i have no ID numbers for my data in excel file and have Not Null at azure sql db and want to auto generate ID on sql server db after the data that is already on the sql server db.

Because the table where data will be stored is having like already 142302 records and i want to generate my uploaded excel file to there and numbering automatically for ID as 142303, 142304 .... So on.

View 1 Replies

Data Controls :: Import CSV File Data To DataTable Using WebService

Apr 27, 2016

I am trying to import a CSV file using web service bt i stuck while displaying it in gridview.

View 1 Replies

Data Controls :: Import (Upload) CSV File Data To DataTable Using MVC

Apr 27, 2016

I want to code for csv file upload and read gridview in visual stuio 2010 MVC 4 ....

View 1 Replies

Data Controls :: Use SqlBulkCopy To Import Bulk Data With Performance

May 7, 2015

How to use SqlBulkCopy for import excel data into windows with high performance.

E.g.: using SqlBulkcopy.TableLock options

View 1 Replies

Import Data Of Excel Into Gridview1

Aug 31, 2010

i m having excel file a.xls i m having gridview1,fileupload1 how to import excel file from fileupload1 get the destination of a.xls and show the values in gridview1

View 3 Replies

Csv File Data Import Into Text Box

Jan 29, 2010

How to import CSV file data into text box. giv me a code.

View 1 Replies

How To Import Data From Other Websites And Use In Project

Sep 7, 2010

i have to implement share market rates in our project how to get that data and how to use the values

View 4 Replies

Databases :: Import Xls Data To MySQL?

Apr 15, 2010

Is there any way to import XLS data into MySQL database which is have similar table structure..?

View 2 Replies

Databases :: Import Data From Excel To SQL?

Mar 30, 2011

How do I do that using c#?

I have a texbox and two buttons.

View 2 Replies

Web Forms :: Mix Datatype Does Not Import All The Data?

Aug 18, 2010

I am using Asp.net2.0 , C#.

I am Uploading the downloaded excel file from asp.net. Now I one of the column I am getting Mix Data type that is int and varchar. But it only show int or varchar that is only one type of data. I am using connection string as

[Code]....

View 5 Replies

Import Excel Data To Oracle DB?

Jan 25, 2010

I want to import excel data to oracle DB.

Is it possible to import to oracledb with filehelpers?

View 3 Replies

Import Data From Either XML Or JSON Feed

Nov 6, 2010

I am going to import some data, and I have the data available in either a JSON feed or a XML feed. I can't decide if I should use the XML or the JSON feed.

What are the pros and cons of choosing either feed, and what is your prefered choice?

View 4 Replies

Web Forms :: How To Import And Export Data

Dec 10, 2011

I have been facing a problem since last two days, actually i want to import some data from a file (file can be csv, txt, sql, xls etc) and after some filtration, export it into csv file. Basically i want to know whether a tool which provides an environment to import different types of file or data where we can perform filtration of data with sql query and then data could be save into file(file can be csv, txt, sql, xls etc)

View 1 Replies

Web Forms :: Import Data From Excel Sheet

Mar 3, 2011

I have a page that import data from an excel sheet and I'm facing a weird problem. The sheet has 47 columns and over almost 72,000 rows. In my workstation I can import the data without problems and I have Office 2010 installed. In the server I have installed AccessDatabaseEngine for Office 2010 and when I try to import the data I receive the following error: The external table is not in the expected format. Rememberring I'm import the data to the same database. But when I break this excel file in files with less rows, it imports without problems.

View 7 Replies

Web Forms :: Import Data From Text And Excel

Feb 10, 2011

I am working on a C# web application under visual studio 2005. I want to import data from text file or excel file into a SQL 2005 database. I have 3 columns in the text file separated by |, example of the text file format:

1|11122222|Name1
2|22299809|Name2

Can you tell me how to import data from text or excel file? Another question, if you provide a solution for the import from excel, can you note which office (2003 or 2007 or 2010)?

View 3 Replies

Import Excel Sheet Data Into Database Using C#

Mar 15, 2010

i am developing an appilication using asp.net 3.5 with c#.net and SqlServer 2005 as backend databse. in my application i have to import the data from excel file to database table.

View 6 Replies

Web Forms :: Import Excel Data Into Fields

Dec 1, 2010

I need an option to load the Asp.net form fields by pulling the excel data.I hav an excel sheet having WoNo,Part,Status,Cust columns, i have same columns on ASP.net webform.when you give input in WoNo field and click on load excel data button corresponding data should be extracted from excel to ASP.net form fields.

View 6 Replies

Import Excel Data To Sql Server 2000?

May 17, 2010

I have import .xls file data into sql server 2000 .

but in my pc i have installed excel 2007 .

which content type is use when i export data from gridview to excel .

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved