PC Review


Reply
Thread Tools Rate Thread

Data Source for mdb connection

 
 
esroinc@msn.com
Guest
Posts: n/a
 
      16th Feb 2007
Would like to replace Data Source mdb location and name with a string
variable. For example:

where I have

@"Data Source = c:\mydirectory\mydatabase.mdb;" +

the c:\mydirectory\mydatabase.mdb would be replaced with a variable.

Thanks Bob J.

 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      16th Feb 2007
Hi,

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Would like to replace Data Source mdb location and name with a string
> variable. For example:
>
> where I have
>
> @"Data Source = c:\mydirectory\mydatabase.mdb;" +
>
> the c:\mydirectory\mydatabase.mdb would be replaced with a variable.


I do not understand where is the problem, you can have the connection string
split in several string vars and just do like

OleDbConnection c = new OleDbConnection( str1 + str2 );


--
Ignacio Machin
machin AT laceupsolutions com


 
Reply With Quote
 
Michael Nemtsev
Guest
Posts: n/a
 
      16th Feb 2007
Hello (E-Mail Removed),

Maybe u need to use smth like string.Format("Data Source = {0};" , YouString)?!

> Would like to replace Data Source mdb location and name with a string
> variable. For example:
>
> where I have
>
> @"Data Source = c:\mydirectory\mydatabase.mdb;" +
>
> the c:\mydirectory\mydatabase.mdb would be replaced with a variable.
>
> Thanks Bob J.
>

---
WBR, Michael Nemtsev [C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


 
Reply With Quote
 
esroinc@msn.com
Guest
Posts: n/a
 
      16th Feb 2007
On Feb 16, 11:12 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com> wrote:
> Hi,
>
> <esro...@msn.com> wrote in message
>
> news:(E-Mail Removed)...
>
> > Would like to replace Data Source mdb location and name with a string
> > variable. For example:

>
> > where I have

Ignacio,

I wish it was that easy. Here is what I'm actually using:

strDBLocation=@"Provider=Microsoft.JET.OLEDB.4.0;Data Source=f:
\Cresi2\MyStuff.mdb;Jet OLEDBatabase Password="+DBPassWord;

If I substitute a variable after Data Source =, the compiler will not
coginize it. The only place where I have been able to substitue a var
is at the end. I have tried to break this down into different strings
and add them to gether, but nothing works.

>
> > @"Data Source = c:\mydirectory\mydatabase.mdb;" +

>
> > the c:\mydirectory\mydatabase.mdb would be replaced with a variable.

>
> I do not understand where is the problem, you can have the connection string
> split in several string vars and just do like
>
> OleDbConnection c = new OleDbConnection( str1 + str2 );
>
> --
> Ignacio Machin
> machin AT laceupsolutions com



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      16th Feb 2007
Hi,

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 16, 11:12 am, "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
> laceupsolutions.com> wrote:
>> Hi,
>>
>> <esro...@msn.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>> > Would like to replace Data Source mdb location and name with a string
>> > variable. For example:

>>
>> > where I have

> Ignacio,
>
> I wish it was that easy. Here is what I'm actually using:
>
> strDBLocation=@"Provider=Microsoft.JET.OLEDB.4.0;Data Source=f:
> \Cresi2\MyStuff.mdb;Jet OLEDBatabase Password="+DBPassWord;


string db = @"f:\Cresi2\MyStuff.mdb";

string strDBLocation = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + db
+ ;Jet OLEDBatabase Password="+DBPassWord;


That should work.

Ps:
I think that using String.Format improve the readiness:

string strDBLocation = String.Format(
"Provider=Microsoft.JET.OLEDB.4.0;Data Source={0}atabase Password={1}",
DBLocation , DBPassWord );



--
Ignacio Machin
machin AT laceupsolutions com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing:Data Connection Wizard Doesn't see Source Data - No Impo Exotic Hadron Microsoft Excel Misc 0 1st Oct 2008 07:35 PM
Data Source connection failing =?Utf-8?B?cmljaw==?= Microsoft VB .NET 0 8th Nov 2007 04:39 PM
ODBC Data Source Connection Problem =?Utf-8?B?TGluY29sbiBC?= Microsoft Access VBA Modules 0 7th Jun 2007 05:08 PM
Urgent help About data source connection =?Utf-8?B?QXN0eQ==?= Microsoft Access 2 2nd Feb 2007 06:36 PM
How to use a Connection String in an Access Data Source shapper Microsoft ASP .NET 0 27th Sep 2006 11:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:25 AM.