请检查我的代码 [英] Please check my code

查看:50
本文介绍了请检查我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net(C#)中编写此代码:

How to write this code in asp.net (C#):

public void Update()
        {
            Dictionary<string,> parameters = new Dictionary<string,>();
            parameters.Add("@Param1", param1Value);
            parameters.Add("@Param2", param2Value);
            int rowsAffected = ExecuteNonQuery("yourConnectionString", "yourStoredProcName", parameters);
        }


它显示各种错误.请任何人更正该代码.


It shows various errors. Please any one correct the code.

推荐答案

您好,

我在您的代码中看到的最大错误是您没有定义和初始化Dictionary< tkey,>适当地.在那里,您始终必须定义键的类型和值.

这是我的重构版本:

Hello,

The biggest error I see in your code is that you didn''t define and initialize the Dictionary<tkey,> properly. There you allways have to definie both the type of the key and the value.

Here is my refactored version:

/// <summary>
/// The param 1 value.
/// </summary>
private object param1Value;
/// <summary>
/// The param 2 value.
/// </summary>
private object param2Value;
/// <summary>
/// Method updates the param1Value and param2Value in the DB.
/// </summary>
public void Update()
{
    // Update "object" with the correct type.
    Dictionary<string,object> parameters = new Dictionary<string,object>();
    parameters.Add("@Param1", param1Value);
    parameters.Add("@Param2", param2Value);
    int rowsAffected = ExecuteNonQuery("yourConnectionString", "yourStoredProcName", parameters);
}
/// <summary>
/// Executes a SQL stored procedure.
/// </summary>
/// <param name="yourconnectionstring">The connectionstring to use for the connection.</param>
/// <param name="yourstoredprocname">The storedprocedure to use.</param>
/// <param name="parameters">The parameters for the stored procedure.</param>
/// <returns>How many rows were affected by the storedprocedure execution.</returns>
private int ExecuteNonQuery(string yourconnectionstring, string yourstoredprocname, Dictionary<string, object> parameters)
{
    // Update the "parameters" param with the correct signature (example: Dictionary<string, string> if the values are all strings).
    // Implement your code here.
    return 0;
}



希望这会有所帮助.

致以诚挚的问候,祝您编程愉快,
停止



Hope this helps.

Best regards and happy coding,
Stops


首先,字典需要两个参数:
First off, a dictionary requires two parameters:
Dictionary<string,string> parameters = new Dictionary<string,string>();

那应该摆脱一些错误...

That should get rid of a few errors...


这篇关于请检查我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆