Get the App
SLTechnology News&Howtos  ›  Development  › 

Steps for C # to call Oracle database

Shulou Source: shulou.com Published: 2022-06-03 16:28:17 09月14日 Update

This article introduces the relevant knowledge of "the steps of C # calling Oracle database". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

C # call Oracle database step 1 data table

Student (studentid varchar2 studentname varchar2)

Data:

Studentid studentname

001 001

002 002

002 003

Step 2: C # calls Oracle database to build a package

CREATE OR REPLACE PACKAGE PKG_SELECT_STUDENT AS TYPE T_CURSOR IS REF CURSOR; PROCEDURE Getusername (us_id IN Varchar2, cur_name OUT T_CURSOR)

C # calls Oracle database step 3 to build the package

CREATE OR REPLACE PACKAGE BODY PKG_SELECT_STUDENT AS PROCEDURE Getusername (us_id IN varchar2, cur_name OUT T_CURSOR) IS BEGIN OPEN cur_name FOR SELECT * FROM student WHERE studentid=us_id; END Getusername; END PKG_select_student

C # call Oracle database step 4 my webform.cs file

Enter ID in the text box and click the button to query. Multiple data fills are displayed in the gatagrid.

Private void Button3_Click (object sender, System.EventArgs e) {string usid=this.TextBox1.Text.Trim (); Selectop st=new Selectop (); this.DataGrid1.DataSource=st.GetSelectAll (usid); this.DataGrid1.DataBind ();} public DataSet GetSelectAll (string usid) {OracleConnection con = DBoracle.CreateConnection (); OracleCommand command = new OracleCommand (); DataSet ds = new DataSet (); try {command.Connection=con; command.CommandText= "PKG_select_student.Getusername"; command.CommandType=CommandType.StoredProcedure Command.Parameters.Add ("us_id", OracleType.VarChar,10) .value = usid; command.Parameters.Add ("cur_name", OracleType.Cursor); command.Parameters ["cur_name"]. Direction = ParameterDirection.Output; OracleDataAdapter adapter = new OracleDataAdapter (command); con.Open (); / / command.ExecuteNonQuery (); / / adapter.SelectCommand=command; adapter.Fill (ds);} catch (System.Exception ex) {throw ex;} finally {con.Close () Command.Dispose (); / / adapter.Dispose ();} return ds;} "steps for C # to call Oracle database" are here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Data database clips steps content more knowledge practicality achievement next dilemma multiple actual situation button datasheet file text article case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info MySQL Xiaomi Redmi