mysql - 如何在 mysql 过程中读取字典数据

标签 mysql asp.net-mvc dictionary stored-procedures

我在这个方法中有字典类型的数据

public Dictionary<string, string> TracingFailed(string AgentIp, string AgentId, string SessionId)
{

    Dictionary<string, string> LogData = new Dictionary<string, string>();
    LogData.Add("Agent_Id", AgentId);
    LogData.Add("login_time", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
    LogData.Add("login_response", "Login Successfully");
    LogData.Add("SessionId", SessionId);
    LogData.Add("IP_Address", AgentIp);
    LogData.Add("NLogin_time", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
    return LogData;
}

我有一个以键名显示的列值表。建议我如何创建一个 mysql 过程,以便可以将此数据发布到该过程并插入到表中。建议我。请

这里我调用这个方法。

Dictionary<string, string> LogData = objDal.TracingFailed(AgentIp.ToString(), modelData.AgentId.ToString(), SessionId);
objDal.InsertLog(LogData);

方法定义。插入 lOG。

public void InsertLog(Dictionary<string, string> LogData)
        {
            string Procedure = "SP_LoginLog";
            ExecuteNonQuery(Procedure, CommandType.StoredProcedure,new MySqlParameter[] {new MySqlParameter("@columnName",LogData.Keys),new MySqlParameter("@ColumnValue",LogData.Values)});

        }

为此我创建了一个程序。

SP_LoginLog

Delimiter //
create procedure SP_LoginLog(in ColumnName varchar(300),in ColumnValue varchar(300))
begin
set @sql=concat("insert into login_log("'ColumnName'")values("'ColumnValue'")");
prepare stmt from @sql;
execute stmt;
end //
Delimiter;

最佳答案

在SQL Server中有一个叫做Table Value Parameter的东西,但是MySql没有这个。因此,您可以尝试创建一个临时表,然后使用 LOAD DATA,如图所示 here将数据推送到临时表中。然后将临时表的名称传递到您的存储过程中。

关于mysql - 如何在 mysql 过程中读取字典数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41627416/

相关文章:

javascript - 如何使用ajax发送文件?

python - Pandas 按列分组并转换为键 :value pair

asp.net-mvc - 如何检查按下了哪个提交按钮?

mysql使用索引的case when语法

mysql - Logstash:Elasticsearch 的未知设置 ‘“index”

java - 上传 MySQL 数据库并从远程系统访问 Java 应用程序

asp.net-mvc - 获取记录时出错 "LINQ to Entities does not recognize the method"

python - 元组列表,第一个元组作为键,按键分组到字典中

python - 递归访问嵌套字典的路径和值

php - 人气算法