2013-07-22 20 views
-2

我面對這個非常簡單的查詢這個問題。我不明白其背後的原因。ORA-01036:一個簡單的查詢的非法變量名稱/數字

string strCon=myConnectionString; 
    string strSql=string.Format("select * from tblUser where UserName like '{0}%'",":Name"); 
    OracleConnection conn = new OracleConnection(strCon); 
    OracleCommand command = null; 
    command = new OracleCommand(strSql, conn); 
    command.CommandType = CommandType.Text; 
    //Getting this value from a function it is a string type variable 
    val = val.Trim().ToUpper().Replace("'", "''"); 
    command.Parameters.Add("Name", OracleType.VarChar, 80).Value = val; 
    DataSet dsEmail = new DataSet(); 
    OracleDataAdapter da = new OracleDataAdapter(command); 
    da.Fill(dsEmail); 
+1

select * form ?? – ajmalmhd04

+0

在添加Name參數後,你的'strSql'是什麼?和**選擇* FORM **?另外考慮使用[參數化的sql](http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html) –

+0

請考慮一些其他的方式這樣做。任何人都可以注入一些SQL ... – Peter

回答

0

最後我找到了我的問題的解決方案。我在查詢中犯了一個錯誤,它不正確。正確的語法是

string strSql=string.Format("select * from tblUser where UserName like {0} || '%'",":Name"); 
相關問題