I’ve got some information in a database that I want to drop in “Notes”.
Is it possible to use System.data.OleDb.OleDbConnection?
I’m trying to do this with:
Dim con As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
Dim dbProvider As String
Dim dbSource As String
dbProvider = “PROVIDER=Microsoft.Jet.OLEDB.4.0;”
Dim source As String = App_Path & “\Settings\AddressBook.mdb”
dbSource = "Data Source = " & source
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = “select * FROM tblcontacts WHERE Voornaam = '” & voornaam & “’ AND ACHTERNAAM = '” & achternaam & “’ AND GEBOORTEDATUM = '” & geboortedatum & “'”
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, “AddressBook”)
con.Close()
Dim notes = ds.Tables(“AddressBook”).Rows(0).Item(“Notes”)
RhinoDoc.ActiveDoc.Notes = notes
Some words are in Dutch but I think its clear what i mean but it is not working. I checked the location of the database and it’s on the right position. Also the select * FROM tblcontacts WHERE Voornaam = ‘" & voornaam & "’ AND ACHTERNAAM = ‘" & achternaam & "’ AND GEBOORTEDATUM = ‘" & geboortedatum & "’" should also be right because I’m using this somewhere else too this way.
One possibility that comes to mind is that your command strings are not actually being assembled the way you intended. Have you tried putting a Debug.Print before the con.ConnectionString= and after the sql= statements? When I do this I like to use the form Debug.Print(“DebugOutputLabel = |” & StringToCheckFormatOf & “|”). The vertical bars will delimit the exact start and finish of the string being checked so as to clearly show any leading and trailing spaces. It might be useful to check whether the database is open and accessible by just printing out con.recordcount or other database property that doesn’t need a select statement right after you open it.
I’ll test it when I’m behind my own computer. Thanks for the fast reply.
Btw. Rhino doesnt automatticly load the system.data.dll can the problem have to do with this?
well if I only load OleDb.OleDbConnection it will not get recognized in need to Imports System.Data first and add the dll by hand.
should it work then?
well I use the code above exactly the same in a normal form and it works. Now I try to use it in a command and it doesnt.
Same select conditions and everything but nothing
Having the code run in Rhino should not make a difference. Does Visual Studio give you any information about the error when you run the code in the debugger? Is an exception thrown or does your code just silently fail?
But I can built it without a problem. Then I just drag it into Rhino. Run my command and nothing after con.open().
If I put a msgbox(“hi”) before it it will show. After. Nothing. So it seems it can’t open the connectionstring. I’ve checked the location where it should open and it’s good (PROVIDER=Microsoft.Jet.OLEDB.4.0; C:\AddressBook.mdb) Just coppied it to C:/ to be sure and changed the “select * FROM tblcontacts WHERE Voornaam = ‘Niels’” to something simpler to test. Nothing
I would highly recommend getting the debugger to work before attempting anything else. Debugging by placing message boxes and print statements in the code is going to slow and painful.
The path used to start the debugger appears to be incorrect for your system. Try opening the .user file for your project and locate the path to the Rhino.exe make sure this matches what is on your computer. Make these edits while visual studio and rhino are closed.
I don’t have a copy of VB express installed at the moment or I would have a better description of the steps needed.
I can put a red dot before it to debug where the command stops normally when I program. But now it doesnt do anything. The red dot appears then : breakpoint cant be hit because no symbols loaded for this document…
Are you building your plug-in for .NET 4? If not, you should change your runtime to .NET 4. That can cause the debugger to get confused and not be able to hit breakpoints.