Asp.net implements the calling of Stored Procedure instances with output parameters, asp.net Stored Procedure
This example describes how to use asp.net to call a stored procedure with output parameters. We will share this with you for your reference. The details are as follows:
Foreground jqurey
<script type="text/javascript"> $(document).ready(function(){ $('#change_image').click(function(){ $('#imgAuthenCode').attr('src','CheckCode.aspx?'+Math.random());}); $("#accounts").bind("blur",function(){ $.ajax({ url:"checkusername.aspx", type:"post", datatype:"html", data:{user_name:$("#accounts").val()}, success:function(msg){$("#tip_accounts").html(msg);} });}); });</script>
Aspx file:
Protected void Page_Load (object sender, EventArgs e) {Entity. user us = new Entity. user (); us. user_name = Request. params ["user_name"]. toString (); if (us. user_CheckName () {Response. write ("<font color = red> the user name already exists. Please try another user name! </Font> ");} else {Response. Write (" <font color = black> the user name can be used! </Font> ");}}
User class
public bool User_CheckName(){ try { string[,] sArray = new string[2, 2]; sArray[0, 0] = "@user_name"; sArray[1, 0] = "@r_id"; sArray[0, 1] = User_name; sArray[1, 1] = null; Factory.SqlModel sm = new Factory.SqlModel(); Id = sm.Proc_Return_R_ID("User_CheckName", sArray); if (Id > 0) { return true; } else { return false; } } catch (Exception e) { Log lg = new Log(); lg.ExceptionError(e); return false; }}
The sqlmodel class must set the type and length of the output parameter. Otherwise, an error occurs.
String [1]: the Size property has an invalid size of 0.
Public int Proc_Return_R_ID (string proc_name, string [,] sArray) {try {if (sArray. getLength (0)> = 1) {DataBase db = new DataBase (); SqlParameter [] sqlpar = new SqlParameter [sArray. getLength (0)]; // Add the returned value for (int I = 0; I <sArray. getLength (0); I ++) {sqlpar [I] = new SqlParameter (sArray [I, 0], sArray [I, 1]);} sqlpar [sArray. getLength (0)-1]. direction = ParameterDirection. output; sqlpar [sArray. getLength (0)-1]. sqlDbType = SqlDbType. int; return db. proc_Return_R_ID (proc_name, sqlpar) ;}else {return 0 ;}} catch {return 0 ;}}
DATABASE. cs class
public int Proc_Return_R_ID(string proc_name, params SqlParameter[] cmdParms){ try { OpenConnection(); if (cmdParms != null) { foreach (SqlParameter parameter in cmdParms) { if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) && (parameter.Value == null)) { parameter.Value = DBNull.Value; } BaseSqlCommand.Parameters.Add(parameter); } BaseSqlCommand.CommandType = CommandType.StoredProcedure; BaseSqlCommand.CommandText = proc_name; BaseSqlCommand.ExecuteNonQuery(); return (int)BaseSqlCommand.Parameters["@r_id"].Value; } else { return 0; } } catch { return 0; } finally { BaseSqlCommand.Parameters.Clear(); CloseConnection(); }}
I hope this article will help you design your asp.net program.
Articles you may be interested in:
- Implementation of calling stored procedure by IDataParameter in asp.net
- A new solution for calling the Stored Procedure Method in ASP. NET
- How to call SQL stored procedures in asp.net to implement Paging
- How to call the oracle stored procedure in asp.net
- Asp.net stored procedure call
- Oracle stored procedure in asp.net (image and text)
- Asp.net uses stored procedures to implement fuzzy search examples
- Implementation Code for ASP. NET to obtain the returned values of Stored Procedures
- Execute SQL statements using stored procedures in ASP. NET
- Asp.net SQL stored procedure
- Asp.net secure, practical, and simple Paging for large-capacity stored procedures
- Asp.net implements the method of calling a stored procedure and returning values