如何传递连接字符串的参数 [英] How to Pass Parameter for Connection String

查看:54
本文介绍了如何传递连接字符串的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我必须使用Diffrent Location中的Excel,而不是Fix Location.Like C:\ Details.xls.

Hi !

I have to use Excel from Diffrent Location not Fix Location.Like C:\Details.xls.

string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Details.xls;Extended Properties=""Excel 8.0;HDR=YES;""";



我正在尝试但没用---
字符串FPath ="C:\ Details.xls";



I am trying but not work ---
string FPath = "C:\Details.xls";

string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ FPath  +";Extended Properties=""Excel 8.0;HDR=YES;""";



请更正.

当我在下面使用Paramereized Code时,它工作正常(从TextBox传递数据库路径)---
字符串str =插入测试SELECT * FROM OPENROWSET("Microsoft.Jet.OLEDB.4.0",''Excel 8.0; Database ="+ txtPath.Text +"'',''SELECT * FROM [Details $] '');



Please Correct it.

As I am using Paramereized Code below, it is working Fine(Database path passing from TextBox) ---
string str = "INSERT INTO Test SELECT * FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 8.0;Database=" + txtPath.Text + "'', ''SELECT * FROM [Details$]'')";

推荐答案

'')";


应该

Shouldn''t

string FPath = "C:\Details.xls";



be



be

string FPath = @"C:\Details.xls";



?

欢呼



?

Cheers


在双引号前加上一个"@"字符:
Stick an ''@'' character in front of the double quotes:
string FPath = @"C:\Details.xls";


假设"\ D"是一个转义字符,这将停止C#编译器...


That stops the C# compiler assuming "\D" is a single escaped character...


这篇关于如何传递连接字符串的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆