.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

Import DataTable into SQL Table

Posted By:      Posted Date: September 14, 2010    Points: 0   Category :Sql Server
I'm trying to parse a text file into a sql table.  I have the code to parse the file and display it in a datatable but for the life of me I can't figure out how to import it into a sql table.  All my previous experience has been with csv files and with schema.ini files.  This is new to me.  This is what the code to read the text file and display it in a datagridview: Dim dtTest As DataTable Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dtTest = New DataTable DataGridView1.DataSource = dtTest.DefaultView End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim filename As String = "C:\Price.txt" Dim lstValues As New List(Of String) Try Using sr As StreamReader = New StreamReader(filename) While Not sr.EndOfStream Dim splits As String() splits = sr.ReadLine.Split(","c) dtTest.Columns.Add(splits(1), GetType(String)) lstValues.Add(splits(2)) End While End Using Catch ex As Exception End Try dtTest.Rows.Add(lstValues.ToArray) End Sub This is what the data in the text file looks like: DD/MM/YYYY HH:MM:SS,LAU4AB,245.35 DD/MM/YYYY HH:MM:SS,ROC06,123.45 DD/MM/YYYY HH:MM:SS,GRE033,87.5 The second item "LAU4AB is the column header for the first

View Complete Post

More Related Resource Links

Import XML File to SQL Table

Here is a brief example of importing an XML file into SQL Server table. This is accomplished by using the BULK option of OPENROWSET to load the file, and then utilizing the XQuery capabilities of SQL Server to parse the XML to normalized table format. This example requires SQL server 2005 or SQL Server 2008.

First, the following XML is saved to XML file C:\Products.xml.

Bulk Copy From Datatable To SQL Server Table


 I have read the data of a excle file and captured the data into the dataset to a datatable, now that data is to be inserted into a SQL Server table using bulk copy option. I am using -

 public bool BulkEnterData(DataTable dt, string tblName)
        SqlBulkCopy bulk = new SqlBulkCopy(con);
        bulk.DestinationTableName = tblName;

        return true;

ERROR Getting-
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.) 

How to resolve the above problem or any other solution is available.


Help creating HTML table from dataTable when every nth dataTable row = 1 html table row... C#

Hello, Im trying to create an html table from data that is in a dataTable but Im having trouble coming up with the right logic. Every 3 rows in the dataTable needs to be 1 row in the html table.  Ive tried using foreach through the datatable with a modulus to determin every third dataTable row but i still run into snags because i am building the table using objects rather than using concatenated strings..(example TableRow tr = new TableRow  etc...). I cant add the cells to the rows when the row is only created in an if statement etc. Can someone post a good example in c# of how they would achieve this. The amount of data in the dataTable could change from time to time so the code cant rely on a pre determined size, unless you just need the total rows and columns, that can be dtermined when the dataTable is filled from the sqlDataReader. <table><tr><td>dataTable row 1 values</td><td>ataTable row 2 values</td><td>dataTable row 3 values</td></tr> <tr><td>dataTable row 4 values</td><td>dataTable row 5 values</td><td>dataTable row 6 values</td></tr>   Any help and example would be great. Ive been able to do similar tables in other apps but thats only when I use concatenated text strings to build the html table. Im trying to stay away from that this time

When to use 'reader' versus a datatable, table adaptor?


I'm making the leap from using all the 'wizards' that are built into VS, and have been doing more with code-behinds.  But, I'm curious as to when/why I should use a reader, versus a databable, table adaptor to "manage" the data returned from a stored procedure.  Typically, the data is to be displayed on a webpage, and not written back to the database.  What's the difference?  When should I use one over another?  

hash table and datatable


I want to store the data in temp table, which is best way to use

hash table or datatable.

Looking forward the reply

Import Access table or Excel spreadsheet into Oracle table


I am trying to import from an Excel spreadsheet or an Access database into an Oracle table.  I used the SSIS Import and Export wizard to create the SSIS packages, but everytime that I attempt to run the package, SSIS stops once it gets to the Pre-Execute phase.  There are never any errors.  Am I doing something that cannot be done?

I'm using the following:  SSIS 2005, Microsoft Oracle OLEDB provider (MSDAORA.1), Excel and Access 2003

By the way, I am able to successfully export from the Oracle database to either Excel or Access using SSIS.


Import Complex XML into flat table


I have an XML feed supplied which I need to get into a SQL Server table. I have tried SSIS but because it has DTD in the file that does not work.

The format is as follows :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE merchantProductFeed SYSTEM "http://www.xxxxx.com/DTD/datafeed.dtd">
   <merchant id="123" name="MerchantName">
    <prod id="123456" in_stock="no" pre_order="no" web_offer="no" hotPick="no" adult="no">
     <text lang="EN">
      <name>Product Name</name> 
      <desc>Product description can be quite long</desc> 
      <spec>Product Specs</spec> 
     <uri lang="EN">
     <price curr="GBP">

Import table data using webservice


Hi all,  I'm starting using web services in .net , I'd like to know how to achieve this:

I need to import table data into a database, currently what we do is uploading via ftp the text files, and then running a process in php in the webserver.

Could this be automated  by sending those text files (or xml, or whatever format is necessary) to a webservice as an argument, and that the webservice handles the insert and validating process of the data?

Also I would need it to be secure, ideally I should send it login validation.

Anybody can help me with this?

Thanks a lot!

Table-valued parameter and DataTable from ADO.NET


I'm going to use TVP:s to enhance performance in my c# .net fw 4 application which uses stored procs in SQL Server 2008. My first test was very successful and I inserted a batch of rows from by using a TVP in a stored proc. So far so good. Now to my question: when looking for the performance profit with SQL Profiler I saw it was really fast, but the generated sql-code made me a little bit confused. My "table" (DataTable class) from the .net-app was "retabled" like this in sql:

declare @table MyTvpType;

insert @table values (1, 2, 3...); ... x number of times

exec MyProc @table;

This was quite surprising, but when examining my .net code, I think there should be som way to "import" my MyTvpType into .net code, and avoid the extra delaration and inserts done as it is now. I'm using this code in .net:

I need to import XML from Cognos to a flat table in SQL Server 2005


How do I query data in this form?

<?xml version="1.0" encoding="utf-8" ?> 
 <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
  xs:schemaLocation="http://developer.cognos.com/schemas/xmldata/1/ xmldata.xsd"

 <item name="NAME_LAST" type="xs:string" length="62" /> 
 <item name="NAME_FIRST" type="xs:string" length="62" /> 
 <item name="NAME_MIDDLE" type="xs:string" length="32" /> 
 <item name="GUID" type="xs:string" length="20" /> 
 <item name="NETID" type="xs:string" length="18" /> 
 <item name="WORK_EMAIL" type="xs:string" length="62" /> 
 <item name="HOME_ADDRESS_STREET_1" type="xs:string" length="50" /> 
 <item name="HOME_ADDRESS_STREET_2" type="xs:string" length="50" /> 
 <item name="HOME_ADDRESS_CITY" type="xs:string" length="32" /> 

Easiest way to Import Multiple Spreadsheets into the same table



I am trying to found out the most simple way to import multiple spreadsheets (myspreadsheet*.xls) into the same table. I found this process relatively straight forward with importing multiple text files (myTextFile*.txt) into the same table.

Any help would be greatly appreciated.

Thanks in advance,


If you have found any of my posts helpful then please vote them as helpful. Kieran Wood MCTS BI, PGD SoftDev (Open), MBCS http://uk.linkedin.com/in/bileeds

out of memory loading datatable from large oracle table


I've created a winform c# application that connects to an oracle database and loads a datatable with all the data in the oracle table then exports it out to a delimited file, which will then get imported to a local mysql database.  This works just fine when the oracle table isn't so large.  However I keep getting an out of memory exception when I populate my datatable with a large oracle table.  I can't manually export data from oracle then manually load to mysql because this has to be seamless to the user.  I'm having difficulties grasping how to solve this problem.  Is there a better solution then what I have to get from oracle to mysql? 

how do i import a text file into a table?


Hi all, need some help here as am not the SQL guru or anything close. I need to write a stored procedure which will import data from a log file into a table in a Database. Right now, i have a log file that looks just like this and i wan to be able to get the data into the appropriate fields in the a table (lets call it tbl_log). I have a service that is creating the log file and i want to be able to import the data into a table, so i need to be able to set the different directories dynamically since there will be different logs in different directories.



C:\TEMP\watch_directory\1\New Folder Created    11/9/2010 5:55:16 PM

C:\TEMP\watch_directory\1\New Folder Renamed to 1\FootBall    11/9/2010 5:55:22 PM

C:\TEMP\watch_directory\1\FootBall\New Folder Created    11/9/2010 5:55:32 PM

C:\TEMP\watch_directory\1\FootBall\New Folder Renamed to 1\FootBall\Dhino    11/9/2010 5:55:35 PM



Please help.

Import Wizard lists table out of order when connected to SQL Azure


When you use the import wizard to copy data from SQL Azure, the list of table on the Azure server is out of order.  This makes it very time consuming to find a particular set of tables. 

Is this something that I could get some feedback on, or perhaps submit as an issue, either here or another forum?



I cannot add a dynamic table inside a Wiki or import a template.


Hello, I Have created a Wiki inside a Sharepoint 2007 site and have created five pages inside this Wiki.   Now I am trying to use a template but there is nowhere that I can import a template. Also, when I attempt to create a dynamic table on one of my Wiki pages, the dialog box which comes up only asks me for the number of columns and rows.  The 'SharePoint How To' book that I am using as an instruction guide is telling me that a dialog box should come up with several parameters, including number of columns, rows, height, depth and formatting - I'm not getting this dialog box.

So, I'm wondering if someone can tell me why:

(a) I can't get a dynamic table into the site where users can add rows and columns.

(b) I can't import a template into the Wiki so we can use a solution that works.

(c) My functionality is restricted. Do I need to be using SharePoint Designer to get this level of functionality?

I'd really appreciate any references which would help me solve this problem.

Thanks for your help.

SharePoint Sally

how to get a SQL table content to a datatable

How to get a SQL table content to a datatable?. I want to make the SQL table content  to view in GridView too.

Import xml data to Table Using Stored procedure



I have xml structure and Table structure as same. I need to import the xml data to Table using stored procedure.

Can you provide sample SP for this?


Thanks in Advance

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