Hi, I'm looking for the basic steps of connection to and editing(Add and deleting tables and data) for a SQL Database inside a VBe Project. I've looked around the net (and the MSDN Help Library) with little success on finding something of this nature that's usable.

If anyone knows how to do this or a good tutorial showing how to learn to do this that's clear on ALL details, it would be extremely helpful.

Re: Visual Basic Express Edition Modifying SQL Data in VBe



First, create the database: Project/Add new item/Sql database (.mdf). Double click on the database in the solution explorer to open it in the Server explorer. Expand the node corresponding to your db, right-click on tables and select Add new table. Then fill the grid with the columns you need and repeat for the other tables. Then you need to create the relationship between the tables. On the diagram node in the server explorer right-click and select new diagram. Select all tables to add them to the diagram. Drag the column from one table to the other to create relationships.

Then you need to create a dataset if it does not exist already. Project/Add new item/Dataset. I'll assume you call it AppData. The dataset will become the data layer of your application.

In the dataset designer, drag all your tables from the server explorer. The server explorer is accessed from View/Server Explorer. You can add a new data connection to your database (sql server, access, odbc...). Save and compile.

Create a new form. Open the Data Source pane (data/show data source) and you will see your dataset as a datasource. I'll assume you'll create a form for table Foo. Next you need to decide if you want a grid view or a detail view. Click on the Foo table in the data source window and you will see a dropdown appear. If you want a detail view instead of a grid change it with this dropdown.

Now drag the table to the empty form. You will see that a grid (or text boxes and labels) will be created with each of the fields. A BindingSource object, a binding navigator, a table adapter and an instance of your dataset are also created. Now switch to code view. You will notice in the Form_Load event some code to load the data and on the save toolstrip code to end editing and validate the data.

Let's suppose you also want to save back the changes to the database. Add this line of code:


That's it. Now you have an application that can insert, delete, update and browse all the data in table Foo.

A whole bunch of good resources, including numerous books, that could really help you out:

ASP.NET 2.0: http://quickstarts.asp.net/QuickStartv20/aspnet/

Winforms: http://www.windowsforms.net/ and http://samples.gotdotnet.com/quickstart/winforms/

The online MSDN Developer's Guide for Windows Form Applications is also indispensible:


They will all teach you the basics of databinding and data access.