Add the Imports statement at the top of the listing by typing. The actual assemblies (fancy .NET speak for DLLs) for database stuff are already referenced in WinForms projects. (You can click the Show All Files button—shown in Figure 4—to see the references to included DLLs.)

Figure 4: Click Show All Files to see all of the legwork Visual Studio has done for you, including adding references to useful assemblies.

The connection string is easy to get, too. Click the Northwind database in the Server Explorer and copy the connection string from the Properties window (see Figure 5). The rest of the code is boilerplate. If you don't want to remember how to write this boilerplate code, you can select it all—after its in Visual Studio one time) and drag and drop in the Toolbox. Then, like everything else in the toolbox, you can drag from the toolbox to your project at any future time.

Figure 5: The connection string can be copied from the Properties window.

Run the project, add some text values, and you are off to the races. You can browse the database table to check your results.

Summary

Older techniques, such as updating a SQL database with inline SQL (like the example in this article), still work. Sometimes, it seems like technology changes exist to sell more software or to torture us. Even though software companies have to sell product to stay in business and sometimes new technologies feel like torture, the general belief is that changes in the way we do things exist to make us more productive.

After 20 plus years of experience, I can tell you that if you are just learning how to update a database in the manner shown, you are fortunate. The reason you are fortunate is that you can tuck this tidbit away and then skip this how-to approach and move on to LINQ. Focusing your energies on LINQ (besides being cooler) will make you immediately more productive and it's a lot more fun than cobbling inline SQL together.

About the Author

Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object-oriented programming and .NET. Check out his book LINQ Unleashed for C#, now available on Amazon.com and at fine bookstores everywhere. Look for his upcoming book Teach Yourself the ADO.NET Entity Framework in 24 Hours. You may contact him for technology questions at pkimmel@softconcepts.com. Paul Kimmel is a Technical Evangelist for Developer Express, Inc.

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.

Thanks for your registration, follow us on our social networks to keep up-to-date