C#mysql Stored procedures and applications

Source: Internet
Author: User

MySQL Stored procedures:

First, execute a stored procedure in the database:

To create a stored procedure named Gettest
Create PROCEDURE gettest ( in xusername varchar ( xpassword varchar from tb_user WHERE username =

Parameter description: In is the incoming parameter, out is the output parameter. And a inout not used.

The SQL statement inside

After execution succeeds, it can be called by call. See if it's successful

Call Gettest ("admin", @password);
Select @password;

This is called for my stored procedure.

After the success, you can go to the VS inside application.

    /// <summary>    ///Storage Structure///Create PROCEDURE gettest (in xusername varchar (+), out Xpassword varchar ( +))///BEGIN///SELECT password into Xpassword from Tb_user WHERE username = xusername; ///End/// </summary>    /// <param name= "username" ></param>    /// <returns></returns>     Publicstring GetPassword (string username) {//return value        stringPassword =NULL; //connecting to a databaseMysqlconnection Mysqlcon = This. Getconn (); Mysqlcon.        Open (); Mysqlcommand Mysqlcommand=NewMysqlcommand (); Mysqlcommand.connection=Mysqlcon; Mysqlcommand.commandtext="gettest";
or "Gettest" is the corresponding stored procedure name. Mysqlcon for database connections
//Mysqlcommand Mysqlcommand = new Mysqlcommand ("Gettest", Mysqlcon);
//Executing stored proceduresMysqlcommand.commandtype =CommandType.StoredProcedure; //set parameter passed in parameter MySQL for? SQL is @Mysqlparameter Username_parameter =NewMysqlparameter ("? xusername", Mysqldbtype.varchar, -);
Assign a value of Username_parameter. Value=username; MYSQLCOMMAND.PARAMETERS.ADD (Username_parameter); Mysqlparameter Password_parameter=NewMysqlparameter ("? Xpassword", Mysqldbtype.varchar, -); MYSQLCOMMAND.PARAMETERS.ADD (Password_parameter);
The output parameter gets the method Password_parameter. Direction=ParameterDirection.Output;
Executive Mysqlcommand.executenonquery (); Password=Password_parameter. Value.tostring (); returnpassword; }
A simple stored procedure is completed for all steps.

C#mysql Stored procedures and applications

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.