开发者

can't access the file path because the folder name contains space and special characters

I am accessing DBF database file which is in hardcoded path, but the folders name contains special character for ex--BSTR-VSD,BSTR~VSD and I can't rename that.

开发者_如何学Python

so when i am making odbc connection say odb and then putting the query into odb.commandText = select * from PATH(hard coded path which contain folder names having special character) then it gives the error

Example:

System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand(); oCmd.CommandText = "SELECT * FROM "+ Pathname + " where DATE_Y >=110 and DATE_M >= " + From_Month + " and DATE_D>=" + From_Day + " and DATE_Y <=110 and DATE_M <= " + To_Month + " and DATE_D<=" + To_Day + " ";

dt_Dbf.Load(oCmd.ExecuteReader());

and exception:: ERROR [42000] [Microsoft][ODBC dBase Driver] Syntax error in FROM clause.


Surround with Brackets

SELECT * 
  FROM ["+ Pathname + "]
 where DATE_Y >=110 
   and DATE_M >= " + From_Month + " 
   and DATE_D>=" + From_Day + " 
   and DATE_Y <=110 
   and DATE_M <= " + To_Month + "
   and DATE_D<=" + To_Day + " "

You can also clean this up using things like betweem StartDate and EndDate


Why not using Parametrized Query? You can use OdbcParameter class.

MSDN: It matches the entire length of the string, including any padding trailing spaces.

        System.Data.Odbc.OdbcCommand oCmd = oConn.CreateCommand();
        oCmd.CommandText = "SELECT * FROM  @pathname where DATE_Y >=110 and DATE_M >= @from_Month and DATE_D>= @from_Day and DATE_Y <=110 and DATE_M <= @to_Month and DATE_D<= @to_Day";
        oCmd.Parameters.Add(new OdbcParameter("@pathname", Pathname));
        oCmd.Parameters.Add(new OdbcParameter("@from_Month", From_Month));
        oCmd.Parameters.Add(new OdbcParameter("@to_Month", To_Month));
        oCmd.Parameters.Add(new OdbcParameter("@from_Day", From_Day));
        oCmd.Parameters.Add(new OdbcParameter("@to_Day", To_Day));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜