###前提・実現したいこと
Asp.net(c#)でOracle databaseをコネクトしてWeb applicationを作っています。(プラットフォームはVisual Studio2015 Communityです)
Sql developerでfunctionを作ったので、Web application上でユーザーにテキストボックス入力を促し、ボタンクリックでラベルにfunctionの結果表示をするC#の書き方を知りたいです。
*結果を読み取るのはデータベースに接続したままでも、Adapterを使ってDisconnectした状態でもどちらでも構いません。
ユーザーインターフェースにこだわりはありません。
###該当のソースコード
Sql (function)
create or replace function get_cAccess ( p_recipeId in number ) return char is access_type recipe.privateAccess%type; r_access recipe.privateAccess%type; begin select privateAccess into access_type from recipe where recipe_id=p_recipeId; if access_type='Y' then access_type:='N'; elsif access_type='N' then access_type:='Y'; end if; update recipe set privateAccess=access_type where recipe_id=p_recipeId returning privateAccess into r_access; return r_access; end;
Asp.netのcode behind file(C#)(抜粋)
protected void Button1_Click(object sender, EventArgs e) { using (OracleConnection conn = new OracleConnection("RecipeConnectionString")) { using (OracleCommand cmd = new OracleCommand("get_cAccess", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@p_recipeId", OracleDbType.Int32).Value = TextBox1.Text; cmd.Parameters.Add("@access_r", OracleDbType.Char, 1).Direction = ParameterDirection.Output; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); Label1.Text = "Your recipe's accesstype is private 'Y': public 'N' : " + cmd.Parameters["@access_r"].Value.ToString(); } } } }
###前提・実現したいこと
ここに質問したいことを詳細に書いてください
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
###発生している問題・エラーメッセージ
Webアプリケーションは表示されるのですが、P_recipeIdを入力してボタンをクリックすると、cmd.ExecuteNonQueryのところに「Oracle exception was unhandled by user 」が出ます。ちなみにWeb.configのConnectionString名は'recipeConnectionString'です。サーバーにはつながっています。あと、同じページに表示したGridviewの中のデータなどもきちんと表示されております。Functionは完成していて、Sql developer上でP_recipeIdをインプットするとr_accessはきちんとアップデートされます。
回答3件
あなたの回答
tips
プレビュー