mysql儲存過程及c#呼叫標準版
private string shuju_lianjie(string name, string email, string password)
{
//////////////////////////////////////////////////////////////////////////////
///獲取使用者名稱、郵件及設定密碼,增加到資料庫的使用者表後返回該使用者註冊id值,不考慮 安全,僅僅表示程式碼的寫作範例是否合乎要求
///儲存過程為:
///CREATE PROCEDURE `yuan_user_cc`(in xname varchar(100),in xemail varchar(100),in xpassword varchar(100),out xid integer)
///begin
///insert into yuan_user(name,email,password) values(xname,xemail,xpassword);
///select id into xid from yuan_user where name=xname;
///end
//////////////////////////////////////////////////////////////////////////////
Int16 id;//返回的id值
MySqlConnection mysqlcon;
MySqlDataAdapter mysqldata = new MySqlDataAdapter();
DataSet dataset = new DataSet();
mysqlcon = new MySqlConnection("server=localhost; user id=root; password=123; database=yuan_test; pooling=false;charset=gb2312");
mysqldata.SelectCommand = new MySqlCommand();
mysqldata.SelectCommand.Connection = mysqlcon;
mysqldata.SelectCommand.CommandText = "yuan_user_cc";
mysqldata.SelectCommand.CommandType = CommandType.StoredProcedure;
//設定引數,新增到資料庫
MySqlParameter name_parameter = new MySqlParameter("?xname", MySqlDbType.VarChar,100);//mysql的儲存過程引數是以?打頭的!!!!
name_parameter.Value = name;
mysqldata.SelectCommand.Parameters.Add(name_parameter);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MySqlParameter email_parameter = new MySqlParameter("?xemail", MySqlDbType.VarChar, 100);//mysql的儲存過程引數是以?打頭的!!!!
email_parameter.Value = email;
mysqldata.SelectCommand.Parameters.Add(email_parameter);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MySqlParameter password_parameter = new MySqlParameter("?xpassword", MySqlDbType.VarChar, 100);//mysql的儲存過程引數是以?打頭的!!!!
password_parameter.Value = password;
mysqldata.SelectCommand.Parameters.Add(password_parameter);
//++++++++++++++++++++++++++返回值++++++++++++++++++++++++++++++++++++++++++
MySqlParameter id_parameter = new MySqlParameter("?xid", MySqlDbType.Int16,15);//mysql的儲存過程引數是以?打頭的!!!!
id_parameter.Direction=ParameterDirection.Output;
mysqldata.SelectCommand.Parameters.Add(id_parameter);
//+++++++++++++++++++++++++開啟資料庫,插入資料,返回id值+++++++++++++++++++
try
{
mysqldata.Fill(dataset, "yuan_user_cc");
id = (Int16)id_parameter.Value;
return id.ToString();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
return String.Empty;
}
}
{
//////////////////////////////////////////////////////////////////////////////
///獲取使用者名稱、郵件及設定密碼,增加到資料庫的使用者表後返回該使用者註冊id值,不考慮 安全,僅僅表示程式碼的寫作範例是否合乎要求
///儲存過程為:
///CREATE PROCEDURE `yuan_user_cc`(in xname varchar(100),in xemail varchar(100),in xpassword varchar(100),out xid integer)
///begin
///insert into yuan_user(name,email,password) values(xname,xemail,xpassword);
///select id into xid from yuan_user where name=xname;
///end
//////////////////////////////////////////////////////////////////////////////
Int16 id;//返回的id值
MySqlConnection mysqlcon;
MySqlDataAdapter mysqldata = new MySqlDataAdapter();
DataSet dataset = new DataSet();
mysqlcon = new MySqlConnection("server=localhost; user id=root; password=123; database=yuan_test; pooling=false;charset=gb2312");
mysqldata.SelectCommand = new MySqlCommand();
mysqldata.SelectCommand.Connection = mysqlcon;
mysqldata.SelectCommand.CommandText = "yuan_user_cc";
mysqldata.SelectCommand.CommandType = CommandType.StoredProcedure;
//設定引數,新增到資料庫
MySqlParameter name_parameter = new MySqlParameter("?xname", MySqlDbType.VarChar,100);//mysql的儲存過程引數是以?打頭的!!!!
name_parameter.Value = name;
mysqldata.SelectCommand.Parameters.Add(name_parameter);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MySqlParameter email_parameter = new MySqlParameter("?xemail", MySqlDbType.VarChar, 100);//mysql的儲存過程引數是以?打頭的!!!!
email_parameter.Value = email;
mysqldata.SelectCommand.Parameters.Add(email_parameter);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MySqlParameter password_parameter = new MySqlParameter("?xpassword", MySqlDbType.VarChar, 100);//mysql的儲存過程引數是以?打頭的!!!!
password_parameter.Value = password;
mysqldata.SelectCommand.Parameters.Add(password_parameter);
//++++++++++++++++++++++++++返回值++++++++++++++++++++++++++++++++++++++++++
MySqlParameter id_parameter = new MySqlParameter("?xid", MySqlDbType.Int16,15);//mysql的儲存過程引數是以?打頭的!!!!
id_parameter.Direction=ParameterDirection.Output;
mysqldata.SelectCommand.Parameters.Add(id_parameter);
//+++++++++++++++++++++++++開啟資料庫,插入資料,返回id值+++++++++++++++++++
try
{
mysqldata.Fill(dataset, "yuan_user_cc");
id = (Int16)id_parameter.Value;
return id.ToString();
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
return String.Empty;
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-608173/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL儲存過程語句及呼叫MySql儲存過程
- C#呼叫 oracle儲存過程C#Oracle儲存過程
- C#呼叫Oracle儲存過程C#Oracle儲存過程
- mysql如何呼叫儲存過程MySql儲存過程
- c#呼叫儲存過程小記C#儲存過程
- 用PHP呼叫MySQL儲存過程PHPMySql儲存過程
- c / c + + 呼叫mysql儲存過程MySql儲存過程
- mysql 儲存過程,以及mybatis如何呼叫MySql儲存過程MyBatis
- PHP呼叫MYSQL儲存過程例項PHPMySql儲存過程
- mysql-定時呼叫儲存過程MySql儲存過程
- 呼叫儲存過程儲存過程
- MySQL儲存過程詳解 mysql 儲存過程MySql儲存過程
- mysql多次呼叫儲存過程的問題MySql儲存過程
- MySQL 儲存過程/遊標/事務MySql儲存過程
- Winform呼叫儲存過程ORM儲存過程
- perl呼叫儲存過程儲存過程
- jdbc呼叫儲存過程JDBC儲存過程
- SQL 儲存過程裡呼叫另一個儲存過程SQL儲存過程
- ibatis呼叫oracle儲存過程(極簡版)BATOracle儲存過程
- MySQL儲存過程詳解 mysql 儲存過程linkMySql儲存過程
- Mysql儲存過程中使用多遊標MySql儲存過程
- mysql 儲存過程MySql儲存過程
- linux呼叫儲存過程Linux儲存過程
- PB中呼叫儲存過程儲存過程
- java 呼叫oracle 儲存過程JavaOracle儲存過程
- php呼叫mssql儲存過程PHPSQL儲存過程
- java中呼叫儲存過程Java儲存過程
- 在儲存過程A中呼叫儲存過程B的結果儲存過程
- 儲存過程——遊標儲存過程
- 完整的分頁儲存過程以及c#呼叫方法儲存過程C#
- MySql儲存過程的作用及語法MySql儲存過程
- MySql儲存過程—2、第一個MySql儲存過程的建立MySql儲存過程
- MySQL 儲存函式及呼叫MySql儲存函式
- mysql儲存過程整理MySql儲存過程
- MySQL之儲存過程MySql儲存過程
- [MYSQL -23儲存過程]MySql儲存過程
- MYSQL儲存過程管理MySql儲存過程
- mysql儲存過程例子MySql儲存過程