程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql存儲過程及c#調用標准版_MySQL教程

mysql存儲過程及c#調用標准版_MySQL教程

編輯:關於MYSQL數據庫

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;
            }

        } 


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved