I'm new to SQL stuff. All I have is MS SQL Express that came with Visual
Studio 2005, and SQL Server Management Studio Express, which I downloaded
and installed.

I've created a new table, and I have a comma-delimited text file of data I
want in that table.

Can someone tell me the least painful way to import that data into the
table?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Re: Importing Data by TAJ

TAJ
Sun Nov 04 19:18:08 PST 2007

The best way is to Create a table in the database that represents the data
structure. Then use the filestream in System.IO namespace and read the file.
you will have to use some creativity to read until it reaches a comma then
mark that as a field. Do that to create a datarow in a datatable or
arraylist then write that row to the database.

That is one way and in that I would do all your error checking and other
logic required to ensure you are importing what you want. But this uses the
basics and is pretty easy. If you look at other built in methods those can
make your life easier but would take longer to explain.

Tom



"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl...
> I'm new to SQL stuff. All I have is MS SQL Express that came with Visual
> Studio 2005, and SQL Server Management Studio Express, which I downloaded
> and installed.
>
> I've created a new table, and I have a comma-delimited text file of data I
> want in that table.
>
> Can someone tell me the least painful way to import that data into the
> table?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>


Re: Importing Data by Cor

Cor
Sun Nov 04 21:04:51 PST 2007

Jonathan,

A comma seperated file contains datafields, the best way is to set those
datafields one by one in your table.

However if you see the rows as objects, then you can by instance zip them
and set them then as a kind of image/blog whatever you name it in the SQL
server. However as least you have then to make from your CSV file a byte
array.

Be aware that it is not one simple instruction to do the latter, doing it
field by field is much easier and as well better to use.

Cor


Re: Importing Data by Jonathan

Jonathan
Sun Nov 04 21:41:45 PST 2007

Thanks, but I didn't even understand what you mean. I was hoping there was
an import command somewhere, like there is in Access.

I'll write code if I have to, if I can figure out how.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:57FE669C-2242-4512-95BA-43C26135CFF9@microsoft.com...
> Jonathan,
>
> A comma seperated file contains datafields, the best way is to set those
> datafields one by one in your table.
>
> However if you see the rows as objects, then you can by instance zip them
> and set them then as a kind of image/blog whatever you name it in the SQL
> server. However as least you have then to make from your CSV file a byte
> array.
>
> Be aware that it is not one simple instruction to do the latter, doing it
> field by field is much easier and as well better to use.
>
> Cor


Re: Importing Data (Bill Vaughn will you add?) by Cor

Cor
Mon Nov 05 04:23:51 PST 2007

OK,

> Thanks, but I didn't even understand what you mean. I was hoping there was
> an import command somewhere, like there is in Access.
>
> I'll write code if I have to, if I can figure out how.
>

Make from your CSV a dataset with datatable(s) in it using OleDB,

Then create the update from that to your database.
(You can use the commandbuilder for that).
Be aware that there is not a method, which can make from a dataset a
DataBase.

Be aware that the dataset has to have the same schema as your database.
In case that it is not equal you can use the FillSchema method.

-----------------------------------------------------------
For Bill.

If you want to do it only one time, then use by hand one of the by Bill so
often mentioned methods., he knows probably more of them then me.

Bill will give you the address of his book, in my opinion the most practical
books about AdoNet that I know.
(I don't get fees from Bill)

Cor



Re: Importing Data by William

William
Mon Nov 05 10:27:40 PST 2007

This is a multi-part message in MIME format.

------=_NextPart_000_005D_01C81F96.7E2E0600
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ah, none of the above.
ADO and ADO.NET (and all of its predecessors after DB-Library) are QUERY =
interfaces, not designed for bulk operations. It's a waste of time and =
resources to try to use the System.Data classes to import more than a =
few rows of data. If the data is being "manufactured" it still makes =
sense to write it to a delimited file and stream it in via one of the =
bulk copy techniques discussed below.=20

When it's time to import data into SQL Server, the fastest (by an order =
of magnitude or more) is to use the TDS bulk copy approach. This is =
exposed in a number of ways including:
a.. The BCP commandline utility.=20
b.. TSQL BulkCopy operations
c.. DTS/SSIS scripts=20
d.. ADO.NET SqlBulkCopy method.
All of these techniques can import data from anything that can be read =
by a .NET data provider, an OLE DB data provider, and ODBC driver or =
your own custom-written data provider that exposes a DataReader. This =
means other database tables, flat files, text files, delimited =
files--almost anything. These routines can import millions of rows in no =
time. Some Oracle customers buy SQL Server just to get SSIS.=20

My latest book details how to use SqlBulkCopy. BOL shows how to do the =
rest. I'll be happy to show it to you if you come to one of my sessions =
this week at DevConnections in Vegas or at my workshop in Vancouver BC =
on the 26th (see www.devweek.com for availability).

hth

--=20
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no =
rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest =
book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-------------------------------------------------------------------------=
----------------------------------------------
"Jonathan Wood" <jwood@softcircuits.com> wrote in message =
news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl...
> I'm new to SQL stuff. All I have is MS SQL Express that came with =
Visual=20
> Studio 2005, and SQL Server Management Studio Express, which I =
downloaded=20
> and installed.
>=20
> I've created a new table, and I have a comma-delimited text file of =
data I=20
> want in that table.
>=20
> Can someone tell me the least painful way to import that data into the =

> table?
>=20
> Thanks.
>=20
> --=20
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>
------=_NextPart_000_005D_01C81F96.7E2E0600
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16546" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Ah, none of the above.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>ADO and ADO.NET (and all of its =
predecessors after=20
DB-Library) are QUERY interfaces, not designed for bulk operations. It's =
a waste=20
of time and resources to try to use the System.Data classes to import =
more than=20
a few rows of&nbsp;data. If the data is being "manufactured" it still =
makes=20
sense to write it to a delimited file and stream it in via one of the =
bulk copy=20
techniques discussed below. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>When it's time to import data into SQL =
Server, the=20
fastest (by an order of magnitude or more) is to use the TDS bulk copy =
approach.=20
This is exposed in a number of ways including:</FONT></DIV>
<UL>
<LI><FONT face=3DArial size=3D2>The BCP commandline utility. =
</FONT></LI>
<LI><FONT face=3DArial size=3D2>TSQL BulkCopy operations</FONT></LI>
<LI><FONT face=3DArial size=3D2>DTS/SSIS scripts </FONT></LI>
<LI><FONT face=3DArial size=3D2>ADO.NET SqlBulkCopy =
method.</FONT></LI></UL>
<DIV><FONT face=3DArial size=3D2>All of these techniques can import data =
from=20
anything that can be read by a .NET data provider, an OLE DB data =
provider, and=20
ODBC driver or your own custom-written data provider that exposes a =
DataReader.=20
This means other database tables, flat files, text files, delimited=20
files--almost anything. These routines can import millions of rows in no =
time.=20
Some Oracle customers buy SQL Server just to get SSIS. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>My latest book details how to use =
SqlBulkCopy. BOL=20
shows how to do the rest. I'll be happy to show it to you if you come to =
one of=20
my sessions this week at DevConnections in Vegas or at my workshop in =
Vancouver=20
BC on the 26th (see <A =
href=3D"http://www.devweek.com">www.devweek.com</A> for=20
availability).</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>hth</FONT></DIV>
<DIV><BR><FONT face=3DArial size=3D2>--=20
<BR>____________________________________<BR>William (Bill) =
Vaughn<BR>Author,=20
Mentor, Consultant<BR>Microsoft MVP<BR>INETA Speaker<BR></FONT><A=20
href=3D"http://www.betav.com/blog/billva"><FONT face=3DArial=20
size=3D2>www.betav.com/blog/billva</FONT></A><BR><A=20
href=3D"http://www.betav.com"><FONT face=3DArial=20
size=3D2>www.betav.com</FONT></A><BR><FONT face=3DArial size=3D2>Please =
reply only to=20
the newsgroup so that others can benefit.<BR>This posting is provided =
"AS IS"=20
with no warranties, and confers no=20
rights.<BR>__________________________________<BR>Visit </FONT><A=20
href=3D"http://www.hitchhikerguides.net"><FONT face=3DArial=20
size=3D2>www.hitchhikerguides.net</FONT></A><FONT face=3DArial size=3D2> =
to get more=20
information on my latest book:<BR>Hitchhiker's Guide to Visual Studio =
and SQL=20
Server (7th Edition)<BR>and Hitchhiker's Guide to SQL Server 2005 =
Compact=20
Edition=20
(EBook)<BR>--------------------------------------------------------------=
---------------------------------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>"Jonathan Wood" &lt;</FONT><A=20
href=3D"mailto:jwood@softcircuits.com"><FONT face=3DArial=20
size=3D2>jwood@softcircuits.com</FONT></A><FONT face=3DArial =
size=3D2>&gt; wrote in=20
message </FONT><A =
href=3D"news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl"><FONT=20
face=3DArial =
size=3D2>news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl</FONT></A><FONT=20
face=3DArial size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; =
I'm new to SQL=20
stuff. All I have is MS SQL Express that came with Visual <BR>&gt; =
Studio 2005,=20
and SQL Server Management Studio Express, which I downloaded <BR>&gt; =
and=20
installed.<BR>&gt; <BR>&gt; I've created a new table, and I have a=20
comma-delimited text file of data I <BR>&gt; want in that table.<BR>&gt; =

<BR>&gt; Can someone tell me the least painful way to import that data =
into the=20
<BR>&gt; table?<BR>&gt; <BR>&gt; Thanks.<BR>&gt; <BR>&gt; -- <BR>&gt; =
Jonathan=20
Wood<BR>&gt; SoftCircuits Programming<BR>&gt; </FONT><A=20
href=3D"http://www.softcircuits.com"><FONT face=3DArial=20
size=3D2>http://www.softcircuits.com</FONT></A><BR><FONT face=3DArial=20
size=3D2>&gt;</FONT></BODY></HTML>

------=_NextPart_000_005D_01C81F96.7E2E0600--


Re: Importing Data by Jonathan

Jonathan
Mon Nov 05 12:42:21 PST 2007

Bill,

>>>>>
ADO and ADO.NET (and all of its predecessors after DB-Library) are QUERY
interfaces, not designed for bulk operations. It's a waste of time and
resources to try to use the System.Data classes to import more than a few
rows of data.
>>>>>

Can you explain why it's a waste of time? Looking at what I've found so far,
that approach would probably take me, personally, about hundredth of the
time requires to figure out the other stuff. And that takes into
consideration the fact that I've been so far unable to find a simple example
showing how to add records to a database using the System.Data classes.

>>>>>
When it's time to import data into SQL Server, the fastest (by an order of
magnitude or more) is to use the TDS bulk copy approach. This is exposed in
a number of ways including:
a.. The BCP commandline utility.
b.. TSQL BulkCopy operations
c.. DTS/SSIS scripts
d.. ADO.NET SqlBulkCopy method.
All of these techniques can import data from anything that can be read by a
.NET data provider, an OLE DB data provider, and ODBC driver or your own
custom-written data provider that exposes a DataReader. This means other
database tables, flat files, text files, delimited files--almost anything.
These routines can import millions of rows in no time. Some Oracle customers
buy SQL Server just to get SSIS.
>>>>>

Okay...

I guess TDS stands for something but "tds bulk copy" brings up one a single
result on Google, and that wasn't much help.

Let's try this: Can you tell me which of these is available with what I have
(VS2005 and SQL Server Management Studio Express)? Also, any spec of details
on using any of these would be a tremendous help. Maybe even a link of some
sort.

And I have your book "Hitchhiker's Guide to Visual Studio and SQL Server."
Am I understanding correctly that this doesn't step through what I want to
do anywhere? Or how about an example that shows how to add records to a
database from C# (with no controls, Access, or anything else other than C#
and SQL)?

>>>>>
My latest book details how to use SqlBulkCopy. BOL shows how to do the rest.
I'll be happy to show it to you if you come to one of my sessions this week
at DevConnections in Vegas or at my workshop in Vancouver BC on the 26th
(see www.devweek.com for availability).
<<<<<

Sounds good, but I'll be far from Vegas at that time.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


Re: Importing Data by William

William
Mon Nov 05 16:20:46 PST 2007

And, I just wrote a whitepaper on this for Developer.Com.
http://www.developer.com/net/asp/article.php/10917_3702826_1



--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:e$rVhx%23HIHA.4272@TK2MSFTNGP06.phx.gbl...
> Bill,
>
>>>>>>
> ADO and ADO.NET (and all of its predecessors after DB-Library) are QUERY
> interfaces, not designed for bulk operations. It's a waste of time and
> resources to try to use the System.Data classes to import more than a few
> rows of data.
>>>>>>
>
> Can you explain why it's a waste of time? Looking at what I've found so
> far, that approach would probably take me, personally, about hundredth of
> the time requires to figure out the other stuff. And that takes into
> consideration the fact that I've been so far unable to find a simple
> example showing how to add records to a database using the System.Data
> classes.
>
>>>>>>
> When it's time to import data into SQL Server, the fastest (by an order of
> magnitude or more) is to use the TDS bulk copy approach. This is exposed
> in a number of ways including:
> a.. The BCP commandline utility.
> b.. TSQL BulkCopy operations
> c.. DTS/SSIS scripts
> d.. ADO.NET SqlBulkCopy method.
> All of these techniques can import data from anything that can be read by
> a .NET data provider, an OLE DB data provider, and ODBC driver or your own
> custom-written data provider that exposes a DataReader. This means other
> database tables, flat files, text files, delimited files--almost anything.
> These routines can import millions of rows in no time. Some Oracle
> customers buy SQL Server just to get SSIS.
>>>>>>
>
> Okay...
>
> I guess TDS stands for something but "tds bulk copy" brings up one a
> single result on Google, and that wasn't much help.
>
> Let's try this: Can you tell me which of these is available with what I
> have (VS2005 and SQL Server Management Studio Express)? Also, any spec of
> details on using any of these would be a tremendous help. Maybe even a
> link of some sort.
>
> And I have your book "Hitchhiker's Guide to Visual Studio and SQL Server."
> Am I understanding correctly that this doesn't step through what I want to
> do anywhere? Or how about an example that shows how to add records to a
> database from C# (with no controls, Access, or anything else other than C#
> and SQL)?
>
>>>>>>
> My latest book details how to use SqlBulkCopy. BOL shows how to do the
> rest. I'll be happy to show it to you if you come to one of my sessions
> this week at DevConnections in Vegas or at my workshop in Vancouver BC on
> the 26th (see www.devweek.com for availability).
> <<<<<
>
> Sounds good, but I'll be far from Vegas at that time.
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>


Re: Importing Data by Andrew

Andrew
Mon Nov 05 21:35:57 PST 2007

You could write code as many of the others suggested. Or you could do it
the easy way. Download the 180 day trial of full SQL Server 2005 and
install just the client access & developer tools. It will include include
SQL Server Management Studio. From that you can do a simple import/export.

http://www.microsoft.com/sql/downloads/trial-software.mspx#EXC

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com


"Jonathan Wood" <jwood@softcircuits.com> wrote in message
news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl...
> I'm new to SQL stuff. All I have is MS SQL Express that came with Visual
> Studio 2005, and SQL Server Management Studio Express, which I downloaded
> and installed.
>
> I've created a new table, and I have a comma-delimited text file of data
> I want in that table.
>
> Can someone tell me the least painful way to import that data into the
> table?
>
> Thanks.
>
> --
> Jonathan Wood
> SoftCircuits Programming
> http://www.softcircuits.com
>


Re: Importing Data by Jonathan

Jonathan
Thu Nov 29 17:11:43 PST 2007

Just to clarify, are you saying that the full version of SQL Server
Management Studio has a completely different way of importing data than the
Express version does?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"Andrew Faust" <andrew@andrewfaust.com> wrote in message
news:0729DD93-51F6-40B6-9B27-1B27F496DC83@microsoft.com...
> You could write code as many of the others suggested. Or you could do it
> the easy way. Download the 180 day trial of full SQL Server 2005 and
> install just the client access & developer tools. It will include include
> SQL Server Management Studio. From that you can do a simple import/export.
>
> http://www.microsoft.com/sql/downloads/trial-software.mspx#EXC
>
> --
> Andrew Faust
> andrew[at]andrewfaust.com
> http://www.andrewfaust.com
>
>
> "Jonathan Wood" <jwood@softcircuits.com> wrote in message
> news:%239kZoJ0HIHA.4584@TK2MSFTNGP03.phx.gbl...
>> I'm new to SQL stuff. All I have is MS SQL Express that came with Visual
>> Studio 2005, and SQL Server Management Studio Express, which I downloaded
>> and installed.
>>
>> I've created a new table, and I have a comma-delimited text file of data
>> I want in that table.
>>
>> Can someone tell me the least painful way to import that data into the
>> table?
>>
>> Thanks.
>>
>> --
>> Jonathan Wood
>> SoftCircuits Programming
>> http://www.softcircuits.com
>>
>