• MySql.Data.dll 不支持输出参数


    insert INTO stu(name) VALUES('maimai');
    set @ReturnValue=@@IDENTITY;

      

    string sql="insert INTO stu(name) VALUES(@name);set @ReturnValue=@@IDENTITY;
     MySqlParameter[] parameters = {
    		new MySqlParameter("@name", MySqlDbType.VarChar,100),MySqlDbType.Int32,1),
                    new MySqlParameter("@ReturnValue",MySqlDbType.Int32)
                       };
    

      

    
    
    public static int ExecuteSql(string SQLString, params MySqlParameter[] cmdParms)
            {
                using (MySqlConnection connection = new MySqlConnection(connectionString))
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        try
                        {
                            PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                            int rows = cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                            return rows;
                        }
                        catch (MySql.Data.MySqlClient.MySqlException e)
                        {
                            throw e;
                        }
                    }
                }
            }
    
    
         private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, string cmdText, MySqlParameter[] cmdParms)
            {
                if (conn.State != ConnectionState.Open)
                    conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = cmdText;
                if (trans != null)
                    cmd.Transaction = trans;
                cmd.CommandType = CommandType.Text;//cmdType;
                if (cmdParms != null)
                {
    
    
                    foreach (MySqlParameter parameter in cmdParms)
                    {
                        if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
                            (parameter.Value == null))
                        {
                            parameter.Value = DBNull.Value;
                        }
                        cmd.Parameters.Add(parameter);
    
    
                    }
                }
            }
    
    
    

     然后执行 

    ExecuteSql(sql,parameters);

    想要返回 return 1(int)parameters[1].Value;

    发现报错 : near  NULL=@@IDENTITY;

    问题:难道是mysql.data 把输出参数的null值也带入sql语句了?

    最后呈现我们的是:insert INTO stu(name) VALUES('maimai');set NULL=@@IDENTITY;

    根源还是没解决,有大神知道的麻烦解决下,下的mysql.data的源码 调试一直进不去,就没接着调试了...

    
    
    
    
  • 相关阅读:
    TweenMax参数补充
    jQuery.lazyload详解
    js函数和jquery函数详解
    数数苹果手机中的不科学
    网页全栈工程师要点分析
    瞄了一眼墙外的世界,只能给差评
    脑洞大开的自然语言验证码
    别再迷信 zepto 了
    产品列表页分类筛选、排序的算法实现(PHP)
    大学回顾和C与PHP之路
  • 原文地址:https://www.cnblogs.com/baicaocanhua/p/6077452.html
Copyright © 2020-2023  润新知