On The Right Track [RESOLVED]

WackoWolf

Active member
Joined
Jan 6, 2006
Messages
39
Location
Rhode Island
Programming Experience
Beginner
I think I am on the right track. At least I hope I am. I am useing the "OpenFileDialog" to start when the program first runs to find the database. But when I click on the database I get this error. Could someone Please tell me what I am doing wrong. Since this is wrong could someone let me know how to do this right.

Thank You
WackoWolf

Here is the error.

"An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set."

And this is the code.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
currManager = BindingContext(DsNetwork1, "tblFreeIP")
 
[/SIZE][SIZE=2][COLOR=#008000]' Fill The Dataset[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] OpenFileDialog1.ShowDialog = DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]NetWork.dbm = OpenFileDialog1.FileName
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE][SIZE=2]daNetwork.Fill(DsNetwork1)[/SIZE]
[SIZE=2] 
[/SIZE][SIZE=2][COLOR=#008000]' Lock The Text Boxes So They Can't Be Change[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 
[/COLOR][/SIZE][SIZE=2]txtSite.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtEthernet0.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtEthernet1.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtCKID.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtSpeed.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtIPsubnet.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtIPaddress.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtHost.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]txtBroadcast.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]btnSave.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]edit = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Show Position Of Record[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000] 
[/COLOR][/SIZE][SIZE=2]ShowPosition()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff] 
[/COLOR][/SIZE]
 
I finally got it to work the way I wanted, I can connect to the database no matter were it is, even to the flash drive. Also as long as the table I am binding to is in the databse it will connect.
The trick is you have to hard code it with the "Microsoft Jet Driver" and also have the "OpenFileDialog" adapter on the form. I am pasting the code I use to do it.
I didn't find this in a book or on a form, someone from school show me how to do it, its weird because they don't teach you this if you don't ask.
You have to make sure your using the "OleDbConnection" and the "OleDbAdapter".
I am glad this wasn't for school, I would have never got it done on time, but if I still had the class I would have been able to ask the teacher, he wsn't teaching nights this term.


Thanks for all your Help.
WackoWolf

VB.NET:
[SIZE=2][COLOR=#008000]' Fill The Dataset
[/COLOR][/SIZE][SIZE=2]OFDCurrent.ShowDialog()[/SIZE]
[SIZE=2][COLOR=#ff0000]conNetwork.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=" & _[/COLOR][/SIZE]
[SIZE=2][COLOR=#ff0000]"""" & OFDCurrent.FileName & """" & _[/COLOR][/SIZE]
[SIZE=2][COLOR=#ff0000]";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"[/COLOR][/SIZE]
[SIZE=2]daNetwork.Fill(DsNetwork1)[/SIZE]
 
Back
Top