Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New in VB2005 : Imports not working 1

Status
Not open for further replies.

Periko

Programmer
Feb 24, 2003
134
0
0
BE
Hello Folks,

just installed VisualStudio 2005. Used to work in VB6.
Want to connect to my simple test.mdb.
First thing not working : imports xxxxxxx. No matter what i'm specifying after the imports, it gives me an error in the editor. What's wrong ?

Anybody knows how to connect to an odbc-database ? I use oracle and relativity(cobol), connectstring no problem, i used with ado, but what to use in .net ?

Kind regards...
Pedro...
 
All Imports statements must be one of the first few non comment lines in a VB file.

There is intellisense available so type 'imports' and press Ctrl-Space. Should show the top level namespaces. Select the one you want and press tab or enter then press the period key and you get the next level etc.

To add a datasource to your application select the BindingSource component from the ToolBox and double click it to add to your form.

Go to properties of the BindingSource object and select DataSource. This will bring up a dialog to allow you to Add Project Data Source. Click this link and you will enter the Data Source Configuration wizard.

Select Database on the first page and click Next.
Click on New Connection.
For an ODBC database click <other> in the listbox and select .NET Framework Provider for ODBC and click Continue

You should now be in familiar territory and I'll leave you to fill in the rest.

Take a look at the BindingSource component on MSDN for further details.


Bob Boffin
 
Hello Bob,

thx for the tip about the Imports. Now it works. Why should we use this imports anyway ? Is it sth like the references and components in VB6 ?

About the data, I found yet a solution. But I want to program this, not with this wizard. Otherwise, if you use the wizard, can you cut the code somewhere out of it ?

I'm using the datareader oledb for my access2000 databases and for odbc the odbc datareader.
What should I use if I want to add or delete data ? A datatable with a data-adapter ? I took a look and it seems you can add and delete records. But what if I want to change the contents of a record ? How do you do that ?
In vb6 i used the opendynaset, the .add and .edit to add or change and afterwards the .update.

Thx anyway...
Pedro...
 
If you include an Imports statement for a namespace you can omit the full namespace when referring to objects in that namespace. There must be a reference for the assembly as well.

For example if you include Imports System.Data.SqlClient you can create a SqlCommand as follows:

Dim lCmd as New SqlCommand

rather than

Dim lCmd as New System.Data.SqlClient.SqlCommand

or

Dim lCmd as New SqlClient.SqlCommand

The last one works because System and System.Data are implicitly imported into imported into every form.

There is a major difference between ADO and ADO.NET in that ADO.NET works with disconnected record sets. In other words if you Fill a DataTable or a DataSet the whole of the data is held in memory and you can manipulate this data using the methods of the DataTable object. This allows you to Add, Delete or modify any data in the table but it doesn't write it back to the database until you explicitly tell it to do so.

A DataAdpater or a TableAdapter has 4 sets of SQL that it uses to do this.
the SelectCommand which is used to load the data,
the DeleteCommand which is used to delete a record,
the InsertCommand which is used to insert a new record
the UpdateCommand which is used to update a record

As an example when you call the Update method of a DataAdapter it looks at the state of each row in the table and executes the appropriate sql command. You need to provide all these commands but the wizards will generate them for you from the SelectCommand.




Bob Boffin
 
Hello Bob,

thx for this valuable information. This seems to make sense. I'll try this asap.

However, can I use this data/table adapters both with odbc and access-tables ? Or do you suggest me to work for access with the oledb ? Or importing the reference for the dao 3.6, or get rid of that old stuff like dao and ado ?

Kind regards...
Pedro...
 
As far as I know you can use the adapters with any type of database thst supports the necessary SQL commands.

You might find problems with a Text File DB [smile2]


Bob Boffin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top