ADO.Net,C#,Change Datasource

Posted by Raja_89 under Sql Server on 10/1/2015 | Points: 10 | Views : 365 | Status : [Member] | Replies : 2
Hai
Is it possible to change the datasoucrce of oledb
In my Win form app i am using datasource
Example
Actual Connection string
provider=microsoft.ace.oledb.12.0;data source=E:\\aa;extended properties=""excel 12.0;hdr=yesD

How can i change like this
String Str="E:\\aa"
provider=microsoft.ace.oledb.12.0;data source=str;extended properties=""excel 12.0;hdr=yesD

Using this datasource i am reading value in excel and show to user

Regards




Responses

Posted by: Sheonarayan on: 10/1/2015 [Administrator] HonoraryPlatinum | Points: 25

Up
1
Down
You can do like this
String str = "E:\\aa";
"provider=microsoft.ace.oledb.12.0;data source=" + str + ";extended properties=""excel 12.0;hdr=yesD"

or
String str = "E:\\aa";
var connStr = "provider=microsoft.ace.oledb.12.0;data source={0} ;extended properties=\"\"excel 12.0;hdr=yesD "
connStr = string.Format(connStr, str);


Thanks, hope this helps.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 10/2/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
A few more options

string str = "E:\\aa";

a) string str1 = new StringBuilder()

.Append("provider=microsoft.ace.oledb.12.0;data source=")
.Append(str)
.Append(";extended properties=\"\"excel 12.0;hdr=yesD")
.ToString();

b)string str2 = new StringBuilder()
.Append("provider=microsoft.ace.oledb.12.0;data source=")
.Append(str)
.Append(@";extended properties=""""excel 12.0;hdr=yesD")
.ToString();

c)string str3 = string.Concat("provider=microsoft.ace.oledb.12.0;data source=", str, @";extended properties=""""excel 12.0;hdr=yesD");


--
Thanks & Regards,
RNA Team

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response