Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Steps for C # to call Oracle database

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report