Question Databases work with the code and not only with the wizards

kfirba

Well-known member
Joined
Dec 29, 2012
Messages
77
Programming Experience
1-3
Hello!

I have been looking for a good website/book that will provide me the information i need about databases in VB.NET.
All I could find was using the built-in wizards, which isn't enough.

I want a book/website that will teach me how to also work with the code and not only with the wizards.

For example, I want to know how to let the user pick a row in the DataGridView, and by that updating some textboxes and labels and let the user edit the information without using the DataGridView and press the default 'Save' button that the wizard provide. I would like to know how to program a navigator by myself.

I also want the book/website to explain abit more about Adapters, Dataset, DataRow,DataTable and etc. and let me do more dynamically changes during the runtime.


Well, I tried to be as specific as possible :)

Thanks in advance!
 
I would generally recommend anyone doing serious data access in VB.NET to use the Entity Framework. It uses raw ADO.NET under the hood but you are protected from all that by the LINQ to Entities API. That said, I'd also say that it's a good idea for all .NET developers to understand the principles of ADO.NET so that they understand what's going to happen as a result of their LINQ to Entities code.

As for a single source of information, while there may be one, I'm not aware of it. Many web tutorials will give you the basics and various source can provide more detail on specific topics. As for books, you could look for one on ADO.NET specifically. I don't think that it's necessary though. There are plenty of sources around that can give you information about ADO.NET and together they will provide all you need to know.

I'd suggest starting with the MSDN documentation for the System.Data namespace and follow the appropriate links from there. When you find a type or term you want to know more about, search the web. Here are a few useful bits of information that I've compiled myself:

Retrieving and Saving Data in Databases
Saving Images in Databases
ADO.NET Data Containers: An Explanation
Using Parameters in ADO.NET
 
Thanks jmcilhinney!

well, there is one problem.
I'm using databases for school assignments for now, and what I need to know is using access databases in vb.bet.

I would like to learn information from here and there but the problem is, that I don't know where to start from :(

one more important thing, I would like to ask you a question.
I understood that the adapter is the connector between the database and the dataset.
the dataset holds a copy of the database.
But, what does the binding source do? I couldn't understand that..

thanks in advance and have a nice day!
 
It doesn't much matter what database you're using when working with ADO.NET because it has been designed to work basically the same way regardless of the data source. There are even various non-database data sources that can be accessed in basically the same way, e.g. CSV files and Excel workbooks. That first link I provided contains code examples using the SqlClient provider for SQL Server but, as I say in that thread, you can simply swap in the corresponding classes from the OleDb provider and it will work for Access, e.g. OleDbConnection for SqlConnection. You'd have to make sure that you were using the appropriate connection string for Access, which you can find at ConnectionStrings.com. You'd also have to make any necessary adjustments to the SQL code, although everything in that particular thread should work find as is for Access.

As for where to start, like I said, you should start with the MSDN documentation. It will tell you what types are available and what they're for. It will also provide various examples. Once you have that knowledge, you can search online for exactly what you need. You can use general keywords, e.g. "ado.net", or get more specific, e.g. "oledbdataadapter". I would always include "vb.net" as a keyword on a first search and then only remove it if you need to broaden the results.

In short:

DataSet is an in-memory representation of a database. It might map directly to an existing database, partially or not at all.
DataTable is an in-memory representation of a database table. Again, it might an actual table in an actual database or not.
DataColumn represents a database table column and describes the data, e.g. data type.
DataRow represents a record and contains actual data.

OleDbConnection represents a connection between the application and the database.
OleDbCommand represents a SQL command that is executed against a database over a connection.
OleDbDataReader represents a stream of data containing the result set of a query.
OleDbDataAdapter groups up to four commands (SELECT, INSERT, UPDATE and DELETE) together to form a bridge between the database and a DataTable to simply the most common data access operations.

A BindingSource is actually nothing to do with ADO.NET, although the two are often used together. A BindingSource is used to expose a list of data for the purposes of data-binding, i.e. setting up a two-way relationship between an in-memory data source and one or more UI elements. The data source is often a DataTable, where the link to ADO.NET comes from, but doesn't have to be, and the UI elements are the controls on your form, e.g. a ComboBox or DataGridView. The idea is that you can then do everything related to the data via the BindingSource rather than doing different things in different places. For instance, you can sort, filter, navigate and edit the data all via the BindingSource, with all changes then being pushed to both the data source and the UI.
 
Thanks!
im still not sure what the binding source stands for, but I guess I will understand sooner or later.

I have another question.
whats the different between DataAdapterManager and DataAdapterTableName? They both are created by the wizard but I couldn't understand the difference.

thanks in advance!
 
im still not sure what the binding source stands for, but I guess I will understand sooner or later.
Here's an example of how a BindingSource might be used. Let's say that you have a DataTable containing data from a database and you want to display it to the user one record at a time and allow them to navigate through the data using Buttons labelled "Next" and "Previous". You would bind your DataTable to the BindingSource and then bind the BindingSource to your controls, e.g. TextBoxes. That would display the first record by default. When the user clicked the Next button, you would call MoveNext on the BindingSource and that would navigate to the new record and display it in the controls. The user could access all the records one at a time by your calling MoveNext and MovePrevious on the BindingSource in response to their button clicks. Now let's say that you wanted to be able to sort the data based on a specific column. You would do that by setting the Sort property of the BindingSource. If the user wanted to delete the current record you would call RemoveCurrent on the BindingSource. If you wanted to use the current record in code you would get it from the Current property of the BindingSource. Etc, etc.
I have another question.
whats the different between DataAdapterManager and DataAdapterTableName? They both are created by the wizard but I couldn't understand the difference.
When you run the Data Source wizard and create a typed DataSet, it contains one DataTable for each database table. There will also be one TableAdapter for each DataTable. The TableAdapters are very much like DataDapters but, like the DataSet and DataTables, they are customised specifically for your database. The TableAdapterManager is basically just an object that wraps all the TableAdapters up together so that you can call UpdateAll once instead of having to call Update once each for every TableAdapter. There's plenty of information about TableAdapters on MSDN.
 
Thanks! I really appriciate your answers!

so basically, the BindingSource is a class that pretty much saves lot of time for the programmer by giving him functions that he often use instead of letting him write it over and over again, e.g. Move to the next record, instead of moving the row of each column, I can just use the binding source function and the function will do that for me.
that means that I can still have a working program with database without the binding source, but I will have much more work.
is that correct?

and, you said something about binding the binding source to controls on the form. How do I do that , and how do I bind it to multiply controls?

thanks in advance!
 
As I said earlier, the BindingSource is all about providing a single point of contact for working with bound data. Yes, you can work with bound data without a BindingSource but, in most cases, the BindingSource makes it easier to do so.

All controls have a DataBindings property that allows you to bind a property to an object. Check out the MSDN documentation for that property and then look for examples online if required.
 
As I said earlier, the BindingSource is all about providing a single point of contact for working with bound data. Yes, you can work with bound data without a BindingSource but, in most cases, the BindingSource makes it easier to do so.

All controls have a DataBindings property that allows you to bind a property to an object. Check out the MSDN documentation for that property and then look for examples online if required.

Thanks!

lets say that I don't know anything about oleDB, not even what dataset is, where should I start learning?
 
Back
Top