.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Importing a .txt file

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :ASP.Net
Hi, I'm currently struggling with this problem: - I currently using Microsoft Visual Studio 2008 and the extension for my database in my web application is .mdf - My supervisor gave me two files, student.txt and staff.txt - I needed to import both of these files into my web application and I am new to this language and I have no idea on how to do this. Please provide some codes sample regarding this problem. Thank you.

View Complete Post

More Related Resource Links

While Importing Excel 2007 file to Datatable - headerrow problem


Hi there,


I am trying to simply extract an excel data from an uploaded file an put it into a datatable. In this case the excel file has 3 rows but when I fill the datatable I only see row count of 2.

I tried changing HDR:NO; to HDR:YES and vice versa, but no luck. 

What am I doing wrong? (Note: the excel file cannot have a  headerrow)


string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pFilePath + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR:NO;\"";
            OleDbConnection conn = new OleDbConnection(connstr);
            DataTable dtTables = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
            string strTablename = dtTables.Rows[0]["TABLE_NAME"].ToString();
            string strSQL = "SELECT * FROM [" + strTablename + "]";

            OleDbCommand cmd = new OleDbCommand(strSQL, conn);

            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            //At this point row count=2 which doesn't make sense




importing .csv file into MS SQL 2005

Greetings :-) I need to import data from my excel .csv file into a database in MS SQL server 2005. Can someone show me the steps? Is there a way to do this with a wizard since I'm not a DBA? Thanks in advance for your assistance   .

importing excel file into sql server 2005 in asp .net using c#

Dear friends i want to import excel file into sql server 2005 in asp .net using c# can anyone help me? rgds,RK

Getting error while importing xml file under my SSP

Using Application Definition Designer,I connected to a database and added a table. Then i exported the xml file from Application Definition Designer to my local folder. After that, in Central Administration under my SSP, i tried to import the xml file from my local folder.During the importing process,i got the following error. Application definition was successfully imported. 2 warning(s) found. Consider fixing the warnings and updating the application definition. Warnings  No method instance of type SpecificFinder defined for for application 'BDC ', entity 'GetInfoDetails'. Profile page creation skipped.  No method instance of type SpecificFinder defined for for application 'BDC ', entity 'GetQualification'. Profile page creation skipped.   Please help me to find a solution for this asap.  

Importing XML file getting an error


I'm trying to import an XML file using XML Source but I'm getting an error when I try to generate XSD.

"Unable to infer the XSD from the XML file. The XML contains multiple namespaces."

I have been researching on using an XML Task  instead but I couldn't figure out how to be able to strip the

xmlns:dt="urn:schemas-microsoft-com:datatypes" & dt:dt="xxxxxx"

from the XML source. Without it, I have no issues. Any ideas would be appreciated. Thanks!


  <?xml version="1.0" encoding="ISO-8859-1" ?>

Importing large dat file into sql server database

I have a dat file which consists of thousands of columns which i have to insert into a database. I have to insert the data into multiple datatables. I am looking for the best possible way to do that. I have looked into bulk insert also but is there a better way? something like normalizing the data in the data access layer and inserting into the tables or creating ssis packages? Any help is highly appreciated.

Importing text file datetime string into SQL datetime column



Using SSIS 2008 R2 to import text files.  Two of the fields contained are datetime values in the format "2010-09-24 18:58:29.220".  Ultimately both the date and time need to be extracted with precision to the second, at the very least.  When I import the text file, however, the time value seems to get truncated before the date value's being imported, for an imported result of "2010-09-24 00:00:00.000".

Is my problem with the Flat File Connection Manager?  Regardless of which DataType choice I use for the properties of my datetime values--I've tried every form of date datatype--the imported column values contain the correct date but the wrong time value.

Is there an easy way to import a text file datetime value straight into a datetime column?  Is it possible, or am I trying to shortcut what should be a proper process?


Importing text file datetime string into SQL datetime column



I'm importing a text file into SQL Server 2008 R2 using SSIS 2008 R2.  Included in the text file is a datetime column with values like "2010-09-24 18:58:29.220".  However, when I import the file, the stored value has the time portion replaced with what I assume is the default, such as "2010-09-24 00:00:00.000".

Is there an easy way to import a datetime value from a text file into a datetime column in my table?  I've tried every form of date datatype in the Flat File Connection Manager, but I still keep getting the correct date portion with the incorrect time portion.

Am I trying to do something that wasn't intended?  I see Todd McDermid's page (http://toddmcdermid.blogspot.com/2008/11/converting-strings-to-dates-in-derived.html) and am starting to wonder if perhaps I'm trying to shortcut something that I shouldn't.


Importing xls file, looking up shortcodes and then exporting to xls or cvs with columns in certain o



I am looking to import an xls file and then for 2 columns in this document I need to look up the shortcodes which are in another document eg London Heathrow is LHR in the lookup table. I need to do that for data in 2 columns and then export the data into xls format or can be cvs, but the column order in the outputted document need to be different to when they were imported how can I go about doing this?

Hope this makes sense

Thanks in advance


SSIS importing fixed length file to sql.


Im trying to import fixed length files to sql. data in it s not importing correct im getting the values incorrect.

it takes the rowdelimiter as also an character and calculating it wrongly. here s my code. if u can plz give some alternate sample code



void CreateSourceColumns()



// get the actuall connection manger instance


IDTSConnectionManagerFlatFile90 flatFileConnection =


Error Importing from .xlsx file to MSQL 2008


Hi All

This is my first post as a new member of this site.

I am trying to import a large .xlsx file into MSQL 2008.

It ran fine up until almost the end of the process then fails. I am completely new at this and would really appreciate some help.

I have included links to the file I am trying to import "AffiliateFutureSoccer - Condenced - Full.xlsx" BUT as this is a fairly large file with a lot of records I have also included a "...Test.xls" version with only 98 lines. Additionally I have also included ".csv" formats of the same files in case they are needed.

Finally, I have included the error report that was generated whilst trying to perform the import. "Report1.txt"

I tried the ...test.csv which has 98 entries and that worked.


Additional info: The files are stored on my Dropbox account, I am an admin on my PC (it's a home PC running Win 7 Ultimate) 

Thanks in advance,


Importing a query from an .mdx file - Support (SSRS 2008)


I'm writing an MDX query which would be used as the main dataset. The issue that I'm facing is that the query is really big because of it's nature of members and requirement and Reporting Services doesn't support the number of characters that I'm using. So I saw this Import button and imported the MDX query. However I don't get the list of members in the fileds section which I can use in the Report Textbox. I was reading http://msdn.microsoft.com/en-us/library/dd239327.aspx and it says that "Importing a query from an .mdx file is not supported"....

My question is would it every be supported? Is there a workaround for what I'm trying above? I would appreicate any help on the same.

Thank you!

Is SQLXMLBulkLoad4Class performance competitive for large file importing


I have posted SQLXMLBulkLoad4Class question in XML and the .NET Framework forum.  No one answered.  Try my luck here.

According to http://msdn.microsoft.com/en-us/library/ms171721.aspx -- "You can insert XML data into a SQL Server database by using an INSERT statement and the OPENXML function; however, the Bulk Load utility provides better performance when you need to insert large amounts of XML data."  I thought "SQLXML Bulkload 4.0 Type Library" was a component to use for fast importing large xml file.

I have created 10 tables with auto increase primary keys and foreign keys in SQL Server database and used the following codes to shred a 390 MB file into those tables without any transformation.  It took me around an hour.  What a disappointment!  Flatting this file into an in-memory table and importing it with SqlBulkCopy or using SSIS only took me around 6 minutes. 

Did anyone experience this?  Is SQLXMLBulkLoad4Class simply just so slow or is it misused by me?




                SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class objBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class();

Trouble importing .dbf file into SQL server 2008 express edition


Hey all,

I'm having trouble exporting my .dbf file into Microsoft SQL server 2008 express edition. I set up an ODBC using a couple different drivers and different versions of the drivers and still got the same error. Below is the error message I am receiving.


TITLE: SQL Server Import and Export Wizard

Could not connect source component.

Error 0xc02020ff: Source - HOSPSITE [1]: The component "Source - HOSPSITE" (1) was unable to retrieve column information for the SQL command. The following error occurred: ERROR [HYS12] [Microsoft][ODBC dBase Driver] Index file not found.


Pipeline component has returned HRESULT error code 0xC02020FF from a method call. (Microsoft.SqlServer.DTSPipelineWrap)



If any one can help that would be greatly appreciated! Thanks!

I am having trouble importing a datetime from a text file.


In my Derived Column Transform editor I have the following

(DT_DBTIMESTAMP)(SUBSTRING(TRIM(Admit_Date),1,4) + "-" + SUBSTRING(TRIM(Admit_Date),6,2) + "-" + SUBSTRING(TRIM(Admit_Date),9,2) + " " + SUBSTRING(TRIM(Admit_Date),11,2) + ":" + SUBSTRING(TRIM(Admit_Date),14,2) + ":00")

The data type column has string [DT_STR] as the value. 

The string looks like 2011-04-04 23:00 

The connection manager has the datatype set to string [DT_STR) with the OutputColumnWidth set to 18

The Admit_Date field is in a temp table created like this [ADMIT_DATE] datetime NULL, 

And below is the error I get

[Derived Column [203]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "component "Derived Column" (203)" failed because error code 0xC0049064 occurred, and the error row disposition on "input column "Admit_Date" (251)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.

Any ideas. Everything I have read tells me to parse the string out like I have, and it works for all my date only fields. e.g. (DT_DBDAT

Quickly: Importing Data from a file?



Thanks for reviewing my question.  I would like to know if its possible in SQL to programmatically import a file (excel or .csv) into its own table to an existing table?

We have a website and I would like to offer the ability to upload a file to the website which will then get imported into the SQL server.

Or should I write an Excel add that imports?

Many Thanks


File Splitter in .Net

I love to do utility programs in .Net. And this is one of them. As I was playing with JSplit (a free file splitter program), I wondered if I could do it in .Net. The framework supports file operations like reading files in bytes and creating them. It is indeed easy to do file operations in .Net Basics on File operations
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend