2013-04-24 55 views
-2

我不斷收到參數名稱錯誤?在底部,我附上了一張圖片來幫助解釋問題。OleDbParameterCollection不包含參數名「」的OleDbParameter

private void loadProgress(string jobNumber) 
    { 

     productioninfo.Open(); 

     OleDbCommand _contractReview = new OleDbCommand ("SELECT [Contract Review] FROM [Main$] WHERE [Job No] = '@Job No'", productioninfo); 
     _contractReview.Parameters.Add("@Job No", OleDbType.Char); 
     _contractReview.Parameters["Job No"].Value = jobNumber; 

     OleDbDataReader dr = _contractReview.ExecuteReader(); 

     while (dr.Read()) 
     { 

     } 
     dr.Close(); 

    } 

![image](https://www.dropbox.com/s/54t7xcfhkj7sghu/Parameter%20name.jpg)

回答

1

嘗試這樣;

OleDbCommand _contractReview = new OleDbCommand ("SELECT [Contract Review] FROM [Main$] WHERE [Job No] = @JobNo", productioninfo); 
_contractReview.Parameters.Add("@JobNo", OleDbType.Char); 
_contractReview.Parameters["JobNo"].Value = jobNumber; 

並且不要在表名和列名中使用空格。不推薦。

結賬Database, Table and Column Naming Conventions?

+0

對excel表格也適用嗎?那是我從 – user2315803 2013-04-25 07:53:14

+0

@ user2315803得到我的信息我不確定excel部分,但你可以嘗試沒有任何空格。 – 2013-04-25 07:54:04