相关疑难解决方法(0)

如何改进数据访问层选择方法模式

最近我发现自己编写数据访问层选择方法,其中代码都采用这种通用形式:

public static DataTable GetSomeData( ... arguments)
{
    string sql = " ... sql string here:  often it's just a stored procedure name ... ";

    DataTable result = new DataTable();

    // GetOpenConnection() is a private method in the class: 
    // it manages the connection string and returns an open and ready connection
    using (SqlConnection cn = GetOpenConnection())
    using (SqlCommand cmd = new SqlCommand(sql, cn))
    {
        // could be any number of parameters, each with a different type
        cmd.Parameters.Add("@Param1", SqlDbType.VarChar, 50).Value …
Run Code Online (Sandbox Code Playgroud)

.net data-access-layer .net-2.0

8
推荐指数
1
解决办法
1万
查看次数

如何以编程方式在C#中使用"using"关键字?

我有一些System.Diagnotics.Processes要运行.我想自动调用close方法.显然,"using"关键字为我做了这个.

这是使用using关键字的方式吗?

foreach(string command in S) // command is something like "c:\a.exe"
{
    try
    {
        using(p = Process.Start(command))
        {
            // I literally put nothing in here.
        }
    }
    catch (Exception e)
    {
        // notify of process failure
    }
}
Run Code Online (Sandbox Code Playgroud)

我想开始多个进程同时运行.

c# process

7
推荐指数
1
解决办法
1659
查看次数

标签 统计

.net ×1

.net-2.0 ×1

c# ×1

data-access-layer ×1

process ×1