I bought vb.net back in 2003 and tried working with it for a few days - then uninstalled in disgust and went back to VB6.
I've just decided its time to try out .net again for some database work with an existing access database. I've just spent the entire night searching for an example of just simply opening an access database from a local disk and stuffing some data into a combobox - with absolutely no success.
The samples that (didn't ) come with vb.net don't seem to be accessable on the MS site any more. It keeps throwing me VB2005 upgrade "opportunities", SQL server stuff, and other unrelated things. WHen I did finally find the 2003 "quickstart" examples, the link goes crazy and locks up IE, showing a path with /doc repeated a couple of dozen times...
Does anyone know where I can get a VB2003 example of just opening a plain-jane NON sql-server access 2000 database and stuffing data from that into a combo
Alternatively, can anyone point me to a modern product similar to the old LINEAR VB6 I still cannot understand why MS eliminated basic from its basic language and substituted C++ without the pointers. If I wanted OOP I'd have bought C++ or Java or something.

vb.net 2003 simple access mdb example? Anywhere?
mr_c
How is this,
VB.NET: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
superior to this:
VB6: Runtime error '-2147217865 (80040e37)'; Table 'account' doesn't exist
In the VB.net case, I'm left scratching my head with only the vaguest idea where to look. In the VB6 case, I'm told exactly what silly mistake I just made. Its the difference between hours of missing the painfully obvious and 10 seconds to switch to the right database. I don't see how devolving the error reporting feature can be considered progress.
This disagreement aside, thank you for the example as it is exactly what I needed to get me started! Too often examples are so fleshed out with all sorts of bells and whistlles that its difficult to see the basic idea inside all the code.
ferlinco
Ok, I went back to VB6 and coded the same basic program (open the DB and stuff a combobox. VB6 told me immediately what the problem was - table does not exist in database. Dummy me, the connection as to a different mdb file than what I thought.
So why is it that ancient old vb6 could just pop up and tell me whats wrong when vb.net could only tell me an exception occured This is what MS considers progress
I remember upgrading from VB4( ) to VB6. Sure, things were hard to figure out at first but everything was actually *better*. Going from VB6 to vb.net feels like the exact opposite.
soanfu
do you mean getting the data from MS Access and putting it into a combobox if so this almost has it with some modifications to be made for you...
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=868748&SiteID=1
use OleDb instead of Sql classes so a conversion for you would be this pretty much...import the System.Data.OleDb namespace then...
Dim theOleDbCommand as new OleDbCommand("SELECT [fieldName] FROM [TableName]", new OleDbConnection(connectionString))
Dim theDataSet as new DataSet()
Dim theDataAdapter as new OleDbDataAdapter(theOleDbCommand)
theDataAdapter.Fill(theDataSet)
Me.cmbNames.DataSource = theDataSet.Tables(0).DefaultView
Me.cmbNames.DisplayMember = "FieldName"
And thats it! You could also do it this way, which would be better in a sense if you are not going to be re-using the dataset for other operations/look ups.
Dim theOleDbCommand as new OleDbCommand("SELECT [fieldName] FROM [TableName]", new OleDbConnection(connectionString))
theOleDbCommand.Connection.Open()
Dim theReader as OleDbDataReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection)
while theReader.Read() = true
Me.theComboBox.Items.Add(theReader(0).ToString())
end while
this will read data line by line and add items retrieves from the first column into the combobox.
R.Tutus
PQSIK
gfmajchrzak
bjquinniii
Penicillin
Fails a the Dim theRead line with "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"
I'm looking at the error messages and cannot make heads not tails of what is supposed to be wrong other than that it says the oledbcommand = nothing (expected since the dim failed).
I used the server explorer to create an oledbconnection to an existing access database then copied the connection string from it into the new oledbconnection below, I figure that would be a foolproof way to get the connection string (included password too).
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim theOleDbCommand As New OleDb.OleDbCommand("SELECT name FROM account", New OleDb.OleDbConnection("see above"))
theOleDbCommand.Connection.Open()
Dim theReader As OleDb.OleDbDataReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection) '<< Fails
While theReader.Read() = True
Me.thecombobox.Items.Add(theReader(0).ToString()) End While
'this will read data line by line and add items retrieves from the first column into the combobox.
End SubTigerPhoenix
I found it easier in VB6 to leave the On Error stuff until after I'd gotten something working as VB6 typically told me enough on its own to let me find and fix the problem. I added the On Error stuff later to prevent ungraceful and/or unnecessary exits.
Is vb.net not capable of describing errors without user's coding everything in themselves