![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Well, I spent about 45 minutes trying to find a simple example that shows how to add records to a SQL database from C# code. All I can find is databound stuff, or examples working with Access and who knows what. How hard can it be? I want to write some code that adds records to an existing table. No controls will be involved (bound or otherwise). Can anyone show me how, or point me in the right direction? Thanks! -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
In short, to get you started... // namespace using System.Data.SqlClient; // Database Connection SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"); // Execute SQL Statement SqlCommand cmd = new SqlCommand("select * from Customers", conn); -------------------- taken from - http://www.csharp-station.com/Tutori.../Lesson01.aspx TAJ "Jonathan Wood" <jwood (AT) softcircuits (DOT) com> wrote in message news:uP2p230HIHA.5520 (AT) TK2MSFTNGP06 (DOT) phx.gbl... Well, I spent about 45 minutes trying to find a simple example that shows how to add records to a SQL database from C# code. All I can find is databound stuff, or examples working with Access and who knows what. How hard can it be? I want to write some code that adds records to an existing table. No controls will be involved (bound or otherwise). Can anyone show me how, or point me in the right direction? Thanks! -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com |
#5
| |||
| |||
|
|
Jonathan, I know that they are hard to find a full configured DataAdapter for that where you have used do one by one the deletes, the updates and the the insert. However if your insert/update/delete is a simple one, then you can use the Commandbuilder. http://www.vb-tips.com/SQLServerUpdate.aspx There are more tips on our website using the commandbuilder and only few to use full written updates. Those needs a lot of code and are therefore not so well to use as tip. Cor |
#6
| |||
| |||
|
|
Thanks, but that code doesn't add any records. Moreover, I couldn't see where the list of articles at the link you provided does either. ? -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com "TAJ" <thomasajenkins (AT) msn (DOT) com> wrote in message news:eWVq9k1HIHA.5520 (AT) TK2MSFTNGP06 (DOT) phx.gbl... In short, to get you started... // namespace using System.Data.SqlClient; // Database Connection SqlConnection conn = new SqlConnection( "Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI"); // Execute SQL Statement SqlCommand cmd = new SqlCommand("select * from Customers", conn); -------------------- taken from - http://www.csharp-station.com/Tutori.../Lesson01.aspx TAJ "Jonathan Wood" <jwood (AT) softcircuits (DOT) com> wrote in message news:uP2p230HIHA.5520 (AT) TK2MSFTNGP06 (DOT) phx.gbl... Well, I spent about 45 minutes trying to find a simple example that shows how to add records to a SQL database from C# code. All I can find is databound stuff, or examples working with Access and who knows what. How hard can it be? I want to write some code that adds records to an existing table. No controls will be involved (bound or otherwise). Can anyone show me how, or point me in the right direction? Thanks! -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com |
#7
| |||
| |||
|
|
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 |
|
Well, I spent about 45 minutes trying to find a simple example that shows how to add records to a SQL database from C# code. All I can find is databound stuff, or examples working with Access and who knows what. How hard can it be? I want to write some code that adds records to an existing table. No controls will be involved (bound or otherwise). Can anyone show me how, or point me in the right direction? Thanks! -- Jonathan Wood SoftCircuits Programming http://www.softcircuits.com |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |