Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralThis is an easy one... really! Pin
codeweenie27-Feb-03 14:25
codeweenie27-Feb-03 14:25 
GeneralRe: This is an easy one... really! Pin
Furty27-Feb-03 14:42
Furty27-Feb-03 14:42 
GeneralRe: This is an easy one... really! Pin
David Stone27-Feb-03 14:42
sitebuilderDavid Stone27-Feb-03 14:42 
GeneralTcpClient.Close Pin
monrobot1327-Feb-03 13:51
monrobot1327-Feb-03 13:51 
GeneralRe: TcpClient.Close Pin
monrobot1328-Feb-03 3:18
monrobot1328-Feb-03 3:18 
GeneralRe: TcpClient.Close Pin
James T. Johnson28-Feb-03 4:54
James T. Johnson28-Feb-03 4:54 
GeneralDeploying an app w/ DB connectivity Pin
Eric VanWieren27-Feb-03 12:36
Eric VanWieren27-Feb-03 12:36 
GeneralRe: Deploying an app w/ DB connectivity Pin
Danny Blanchard5-Mar-03 20:38
Danny Blanchard5-Mar-03 20:38 
Like you, I've written a couple programs that access a database. In order to do this with ADO.NET(which is what I use), you must set up a connection string inside your OleDBConnection object. The connection string gives(among other things) a path to your database file.

When you add a OleDBDataAdapter object to your form, a wizard pops up to help you set up your connection. For example, when I set up a data adapter to my Access database, the designer adds this line of code to my program:

this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source= Path to your file here ;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";

I know that looks like a bunch of jibberish, but what you can do is before you open a connection to your database, modify your connection string to reflect where your database is.

Because you don't know where the user will choose to install your program, you can use the System.Environment.CurrentDirectory property to locate where your application is running from and (assuming your database's location is based on the location of the app) append your database's path and name.

My code to do this looks like this:

string CurrentDir = System.Environment.CurrentDirectory;<br />
CurrentDir += "\\DB\\database.mdb";


this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Password="""";User ID=Admin;Data Source=";<br />
  this.oleDbConnection1.ConnectionString += CurrentDir;<br />
  this.oleDbConnection1.ConnectionString += @";Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";


I hope that helps.

Daniel E. Blanchard
GeneralWeb service client apps docs Pin
gadgetfbi27-Feb-03 10:21
gadgetfbi27-Feb-03 10:21 
QuestionHow to save the TreeView content Pin
j-hannemann27-Feb-03 9:26
j-hannemann27-Feb-03 9:26 
AnswerRe: How to save the TreeView content Pin
jtmtv1827-Feb-03 11:07
jtmtv1827-Feb-03 11:07 
GeneralRe: How to save the TreeView content Pin
j-hannemann27-Feb-03 20:20
j-hannemann27-Feb-03 20:20 
AnswerRe: How to save the TreeView content Pin
Furty27-Feb-03 15:25
Furty27-Feb-03 15:25 
GeneralRe: How to save the TreeView content Pin
j-hannemann27-Feb-03 20:14
j-hannemann27-Feb-03 20:14 
GeneralImage on ListView control's column header Pin
newneo27-Feb-03 8:58
newneo27-Feb-03 8:58 
GeneralRe: Image on ListView control's column header Pin
Furty27-Feb-03 15:10
Furty27-Feb-03 15:10 
GeneralChange icon on custom control Pin
Anonymous27-Feb-03 7:23
Anonymous27-Feb-03 7:23 
GeneralRe: Change icon on custom control Pin
leppie27-Feb-03 8:55
leppie27-Feb-03 8:55 
GeneralRe: Change icon on custom control Pin
Anonymous27-Feb-03 9:44
Anonymous27-Feb-03 9:44 
GeneralRe: Change icon on custom control Pin
Furty27-Feb-03 15:07
Furty27-Feb-03 15:07 
GeneralTreeView OwnerDraw: WndProc(...) How to get item information like ItemRectangle, ItemText, Focused Pin
STW27-Feb-03 6:28
STW27-Feb-03 6:28 
GeneralRe: TreeView OwnerDraw: WndProc(...) How to get item information like ItemRectangle, ItemText, Focused Pin
leppie27-Feb-03 9:08
leppie27-Feb-03 9:08 
GeneralRe: TreeView OwnerDraw: WndProc(...) How to get item information like ItemRectangle, ItemText, Focused Pin
STW28-Feb-03 3:10
STW28-Feb-03 3:10 
GeneralInternet date and time Pin
Bjornar Henden27-Feb-03 5:35
Bjornar Henden27-Feb-03 5:35 
GeneralRe: Internet date and time Pin
David Stone27-Feb-03 7:45
sitebuilderDavid Stone27-Feb-03 7:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.