asp.net C#調用mssql預存程序方法

來源:互聯網
上載者:User

asp教程.net c#調用mssql預存程序方法
按道理來講只要是程式與sql打交道的程式都可以調用mssql預存程序的,下面我們提供了二種asp.net教程 c#調用mssql預存程序方法
*/

  string constr = "data source=test;user id=scott;password=tiger";
  oracleconnection con = new oracleconnection(constr);
  oraclecommand com = new oraclecommand("sp2", con);
  com.commandtype = commandtype.storedprocedure;
  con.open();
  oracleparameter p1 = new oracleparameter("v_empno", oracletype.int32);
  oracleparameter p2 = new oracleparameter("v_sal",oracletype.double);  
  p1.direction = parameterdirection.input;
  p1.value = 7369;
  p2.direction = parameterdirection.output;
  com.parameters.add(p1);
  com.parameters.add(p2);
  com.executenonquery();  
  textbox1.text = com.parameters["v_sal"].value.tostring();
  con.close();
  }
 
  /*
  預存程序建立代碼
 
  create or replace procedure sp2(v_empno number) is
  v_sal number(7,2);
  begin
  update emp set sal=sal+200 where empno=v_empno;
  select sal into v_sal from emp where empno=v_empno;
  dbms_output.put_line('員工號:'||v_empno||' 工資:'||v_sal);
  end;

  */
 
  //調用方法二
 

    direction = parameterdirection.input;
 para.value = 名字;
 sqlparameter para2 = new sqlparameter("@pwd",sqldbtype.char,10);
 para.direction = parameterdirection.input;
 para.value = 密碼;
 sqlparameter para = new sqlparameter("@isvalid",sqldbtype.char,10);
 para.direction = parameterdirection.returnvalue;
 sqlcommand mycommand=new sqlcommand("checkpass",conn)
 mycommand.commandtype=commandtype.storedprocedure;
 mycommand.parameters.add(para);
 mycommand.parameters.add(para2);
 mycommand.excutenonquery();
 bool isvalid=mycommand.parameters["@isvalid"].value; //傳回值
  %>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.