mysql存储过程及调用_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;

}

}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-608173/,如需转载,请注明出处,否则将追究法律责任。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值