WebServices calls stored procedures

Source: Internet
Author: User

Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. diagnostics;
Using system. Web;
Using system. Web. Services;
Using system. Data. oledb;
Using system. Web. Services. Protocols;

Namespace sfxtwebservice
{
/// <Summary>
/// Summary of service1.
/// </Summary>
Public class service1: system. Web. Services. WebService
{
Public service1 ()
{
// Codegen: This call is required by the ASP. NET web service designer.
Initializecomponent ();
}

# Code generated by the region component designer

// Required by the Web Service designer
Private icontainer components = NULL;

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{

}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing & components! = NULL)
{
Components. Dispose ();
}
Base. Dispose (disposing );
}

# Endregion

// Web service example
// Helloworld () Sample Service returns the string Hello World
// To generate a project, uncomment the following lines and save and generate the project
// To test this web service, press F5

# Region sfqd
[Webmethod]
Public dataset getproceduresfqd (string strp_lsh, out string strp_zt)
{
String strdbconnection = "";
Strdbconnection = system. configuration. configurationsettings. receivettings ["conndbstring"];
Oledbconnection oleconn = new oledbconnection (strdbconnection );
Oleconn. open ();
Oledbcommand olecomm = new oledbcommand ("sfxt. sp_sf_bank_sfqd", oleconn); // call the method of the stored procedure
Olecomm. commandtype = commandtype. storedprocedure; // The Name Of The stored procedure.
Try
{


// In Parameters
Olecomm. Parameters. Add (New oledbparameter ("p_lsh", oledbtype. varchar, 50). value = strp_lsh;

// Out Parameter
Olecomm. Parameters. Add (New oledbparameter ("p_zt", oledbtype. varchar, 50 ));
Olecomm. Parameters ["p_zt"]. Direction = parameterdirection. output;

Olecomm. executenonquery (); // executes the Stored Procedure

// Assign a value
Strp_zt = olecomm. Parameters ["p_zt"]. value. tostring ();

String str1 = olecomm. Parameters ["p_zt"]. value. tostring ();

Dataset DS = new dataset ();

Datatable Table1 = new datatable ();
DS. Tables. Add (Table1 );

DS. Tables [0]. Columns. Add ("p_zt ");

Datarow DR = Ds. Tables [0]. newrow ();
Dr [0] = str1;

DS. Tables [0]. Rows. Add (DR );

Return Ds;

}
Catch (exception)
{
Strp_zt = "";
Return NULL;
}
Finally
{
Oleconn. Close ();
Oleconn. Dispose ();
}

}
# Endregion

# Region ysf
[Webmethod]
Public dataset getprocedureysf (string strp_lsh, string strp_ykzje, string strp_csdwdm, string strp_yksh, out string strp_zt, out string strp_errordesc)
{

String strdbconnection = "";
Strdbconnection = system. configuration. configurationsettings. receivettings ["conndbstring"];
Oledbconnection oleconn = new oledbconnection (strdbconnection );
Oleconn. open ();
Oledbcommand olecomm = new oledbcommand ("sfxt. sp_sf_bank_ysf", oleconn); // call the method of the stored procedure
Olecomm. commandtype = commandtype. storedprocedure; // The Name Of The stored procedure.
Try
{

// In Parameters
Olecomm. Parameters. Add (New oledbparameter ("p_lsh", oledbtype. varchar, 50). value = strp_lsh;
Olecomm. Parameters. Add (New oledbparameter ("p_ykzje", oledbtype. varchar, 50). value = strp_ykzje;
Olecomm. Parameters. Add (New oledbparameter ("p_csdwdm", oledbtype. varchar, 50). value = strp_csdwdm;
Olecomm. Parameters. Add (New oledbparameter ("p_yksh", oledbtype. varchar, 50). value = strp_yksh;

// Out Parameter
Olecomm. Parameters. Add (New oledbparameter ("p_zt", oledbtype. varchar, 50 ));
Olecomm. Parameters ["p_zt"]. Direction = parameterdirection. output;
Olecomm. Parameters. Add (New oledbparameter ("p_errordesc", oledbtype. varchar, 50 ));
Olecomm. Parameters ["p_errordesc"]. Direction = parameterdirection. output;

Olecomm. executenonquery (); // executes the Stored Procedure

// Assign a value
Strp_zt = olecomm. Parameters ["p_zt"]. value. tostring ();
Strp_errordesc = olecomm. Parameters ["p_errordesc"]. value. tostring ();

String str1 = olecomm. Parameters ["p_zt"]. value. tostring ();
String str2 = olecomm. Parameters ["p_errordesc"]. value. tostring ();

Dataset DS = new dataset ();

Datatable Table1 = new datatable ();
DS. Tables. Add (Table1 );

DS. Tables [0]. Columns. Add ("p_zt ");
DS. Tables [0]. Columns. Add ("p_errordesc ");

Datarow DR = Ds. Tables [0]. newrow ();
Dr [0] = str1;
Dr [1] = str2;

DS. Tables [0]. Rows. Add (DR );

Return Ds;

}
Catch (exception)
{
Strp_zt = "";
Strp_errordesc = "";
Return NULL;
}
Finally
{
Oleconn. Close ();
Oleconn. Dispose ();
}
}

# Endregion
}
}

 

 

========================================================== ========================

This article is reprinted. You must ensure that this article is complete and the original author information and the link to this Article are fully retained.

E-mail:Khler@163.com

QQ: 23381103

MSN:Pragmac@hotmail.com

Original article: http://www.webasp.net/article/28/27530.htm

========================================================== ========================

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.