Import CSV file to MS Access
-
Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...
-
Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...
You can open the mdb with any .net connection and use the INSERT SQL to import the csv data. Ensure the target table is blank and make a Schema.ini file for define the schema of the csv file. eg. string sql = string.Format("insert into {0} select * from [Text;FMT=Delimited(|);HDR=No;DATABASE={1};].[{2}#csv];", info.TableName, info.FilePath, info.FileName); System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(sql, connection); command.ExecuteNonQuery(); for schema.ini http://msdn.microsoft.com/en-us/library/ms709353.aspx :)
Emimmortal
-
Hi I am new for .Net.... I work with Microsoft Visual Basic 2008 I want to import the csv(comma delimited values) file into my database(Access). I read the file using StreamReader(File IO) instead of database (OLEDB) connection.I read the line and splited each values by 'comma' and stored into an array of strings. The csv file may contain field names or not... Now my problem is i want to read the records from csv file and store into database in appropriate field names in table(access)(I dont know how many records in csv and whether it contains field name or not, and also only selected fields are stored into database.) Can someone explain? Thanks in Advance...
When you create this post it suggested you first search the site and ot Google. This is one of the most asked questions ANYWHERE, do the searches!
Never underestimate the power of human stupidity RAH
-
You can open the mdb with any .net connection and use the INSERT SQL to import the csv data. Ensure the target table is blank and make a Schema.ini file for define the schema of the csv file. eg. string sql = string.Format("insert into {0} select * from [Text;FMT=Delimited(|);HDR=No;DATABASE={1};].[{2}#csv];", info.TableName, info.FilePath, info.FileName); System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(sql, connection); command.ExecuteNonQuery(); for schema.ini http://msdn.microsoft.com/en-us/library/ms709353.aspx :)
Emimmortal
Thanks for your reply.... My target table contains values(master table).I want to add the selected columns( appropriate values) from the csv file to related fields in the master table..(Mapping via field names, if csv doesn't contain field names we can assign...) How is this possible... Please explain...