2010-08-05 83 views
0

我們有一個駐留在oracle 10.2數據庫中的oracle存儲過程。存儲的程序包含特定的輸入和輸出參數。我們正在嘗試創建一個asp.net web應用程序來執行存儲過程,並將來自輸出參數的結果綁定到一個gridview中。但沒有運氣。使用asp.net調用oracle存儲過程。 Visual Studio 2005

這是我迄今所做

Oracle.DataAccess.dll

我與Oracle開發工具Visual Studio已安裝了Oracle數據訪問組件(ODAC),並用它來調用oracle存儲過程。

**這是我得到**
ORA-06550錯誤:第1行,第7列:
PLS-00306:錯號碼或類型的呼叫參數 'CALC_NUMBERVOTES'
ORA-06550 :第1行,第7列:
PLS-00306:錯誤數量或類型的呼叫參數 'CALC_NUMBERVOTES'
ORA-06550:第1行,第7列:
PLS-00306:錯誤的號碼或類型的參數來電 'CALC_NUMBERVOTES'
ORA-06550:第1行,第7列:
PLS-00306 :錯誤的數量或類型的呼叫參數 'CALC_NUMBERVOTES'
ORA-06550:第1行,第7列:
PL/SQL:語句被忽略

任何幫助非常感謝。
oralce的存儲過程代碼

PROCEDURE calc_numbervotes ( 
    i_Office    IN ELECTIONRESULTS.office%TYPE, 
    o_candidate    OUT tblcandidate , 
    o_party     OUT tblparty, 
    o_votes     OUT tblvotes, 
    o_percAll    OUT tblpercAll) 
IS 
/***************Find Number of candidate per office and party******************/ 
CURSOR c1 is 
    SELECT distinct candidate, party,sum(votes) totalvotes 
    FROM ELECTIONRESULTS 
    WHERE candidate not in ('Registered Voters') 
    AND office = i_office 
    AND Precinct <> ' ' 
    GROUP BY candidate,party 
    ORDER BY sum(votes) desc; 
/****************** Find total county votes per candidate *********************/ 
CURSOR c2 is 
    SELECT sum(votes) from ELECTIONRESULTS 
    WHERE candidate !='Registered Voters' 
    AND office  = i_Office 
    AND Precinct <> ' '; 

    recCount  NUMBER DEFAULT 0; 
    totvotesall NUMBER; 
    totvotescandidateprec NUMBER; 

BEGIN 

    OPEN c2; 
    FETCH c2 into totvotesall; 
    CLOSE c2; 
    ************************************************************/ 
    FOR rec in c1 LOOP 

    recCount:= recCount + 1; 

     o_candidate(recCount):= rec.candidate; 
     o_party(recCount) := rec.party; 
     o_votes(recCount) := rec.totalvotes; 

    if rec.totalvotes = 0 then 
     o_percAll(recCount) := 0; 
    else 

     o_percAll(recCount) := round((rec.totalvotes/totvotesall)*100,2); 

    end if; 

    END LOOP; 
END calc_numbervotes; 

asp.net代碼

Dim constr As String = "data source=ds;user id=uid;password=pwd;" 
Dim orclCon As OracleConnection 
orclCon = New OracleConnection(constr) 
Dim objCmd As OracleCommand = New OracleCommand() 
objCmd.Connection = orclCon 
objCmd.CommandText = "pkg_calc_votes.calc_numbervotes" 
objCmd.CommandType = CommandType.StoredProcedure 
objCmd.Parameters.Add(New OracleParameter("i_office", OracleDbType.NVarchar2, 255)).Value = "U.S. CONGRESS 05" 
objCmd.Parameters.Add(New OracleParameter("o_party", OracleDbType.NVarchar2, 10)).Direction = ParameterDirection.Output 
objCmd.Parameters.Add(New OracleParameter("o_candidate", OracleDbType.NVarchar2, 255)).Direction = ParameterDirection.Output 
objCmd.Parameters.Add(New OracleParameter("o_votes", OracleDbType.Decimal, 10)).Direction = ParameterDirection.Output 
objCmd.Parameters.Add(New OracleParameter("o_percAll", OracleDbType.Double, 10)).Direction = ParameterDirection.Output 
orclCon.Open() 
Dim orclDtRdr As OracleDataReader = Nothing 
orclDtRdr = objCmd.ExecuteReader() 
gvCursor.DataSource() = orclDtRdr 
gvCursor.DataBind() 
orclDtRdr.Close() 
orclCon.Close() 

所存儲proceder從表中選擇數據庫中的所有數據,除了一個值,其中_o_percAll_。該參數正在sp中進行計算。

謝謝 教育暨青年局

+0

你的參數類型似乎並不匹配: NVARCHAR2 <> tblCandidate – 2010-08-05 20:27:22

+0

爲什麼需要在存儲過程的輸出參數?爲什麼不返回單個結果集? – 2010-08-05 20:36:50

回答

1

要使用ExecuteReader(),存儲過程需要返回的結果集。您的存儲過程似乎沒有這樣做。考慮這樣做,它返回無需使用輸出參數的設置結果:

CURSOR votes_cur is 
    SELECT sum(votes) from ELECTIONRESULTS 
    WHERE candidate !='Registered Voters' 
    AND office  = i_Office 
    AND Precinct <> ' '; 

    totvotesall NUMBER; 

    OPEN votes_cur; 
    FETCH votes_curinto totvotesall; 
    CLOSE votes_cur; 

    SELECT distinct candidate, party, 
    sum(votes) totalvotes, 
    round((sum(votes)/totvotesall)*100,2) votesPerc 
    FROM ELECTIONRESULTS 
    WHERE candidate not in ('Registered Voters') 
    AND office = i_office 
    AND Precinct <> ' ' 
    GROUP BY candidate,party 
    ORDER BY sum(votes) desc; 

我的PL/SQL技能是隔靴搔癢我的T-SQL技能,但我認爲這可以讓你接近。你甚至可以刪除光標,就像這樣:

totvotesall NUMBER; 

SELECT totvotesall = sum(votes) 
FROM ELECTIONRESULTS 
WHERE candidate !='Registered Voters' 
AND office  = i_Office 
AND Precinct <> ' '; 
1

你的存儲過程有四個輸出參數是PL/SQL關聯數組(大概是,雖然你不顯示究竟怎麼tblcandidate等被定義在你的代碼示例中)。因此,在您的.Net代碼中,您需要指定將四個輸出參數綁定爲pl/sql關聯數組,因此:

o_party.CollectionType = OracleCollectionType。PLSQLAssociativeArray

等等。看到這裏瞭解更多詳情:

OracleCommand Object - Array Binding details