Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL CLR存储过程输出_Sql_Clr_Sqlclr - Fatal编程技术网

SQL CLR存储过程输出

SQL CLR存储过程输出,sql,clr,sqlclr,Sql,Clr,Sqlclr,有一个名为User的简单类及其对象列表 公共类用户 { 公共int ID; 公共字符串用户名; 公共字符串用户密码; } ... List userList=新列表(); 我是否可以将此用户对象列表作为执行SLQ CLR存储过程的结果? e、 我想要这个 ID UserName UserPassword 1 Ted SomePassword 2 Sam Password2 3 Bill dsdsd ID用户名用户密码 1.密码 2山

有一个名为User的简单类及其对象列表

公共类用户
{
公共int ID;
公共字符串用户名;
公共字符串用户密码;
}
...
List userList=新列表();

我是否可以将此用户对象列表作为执行SLQ CLR存储过程的结果? e、 我想要这个

ID   UserName  UserPassword
1    Ted       SomePassword
2    Sam       Password2
3    Bill      dsdsd

ID用户名用户密码
1.密码
2山姆密码2
3条例草案


[SqlProcedure]
公共静态void GetAllocations()
{
//这里是什么??
}

另外,请不要建议我使用Sql函数。它不适合我,因为它不支持输出参数


p.S.2如有任何帮助,我将不胜感激

尝试使用创建虚拟表,并通过对象的属性发送:


你看过林克吗?马塞尔·J·克鲁伯特。我真的很感激你!!!非常感谢!你救了我的命)

ID   UserName  UserPassword
1    Ted       SomePassword
2    Sam       Password2
3    Bill      dsdsd

[SqlProcedure]
public static void GetAllocations()
{
    // what here ??
}
[SqlProcedure]
public static void GetAllocations()
{
    // define table structure
    SqlDataRecord rec = new SqlDataRecord(new SqlMetaData[] {
        new SqlMetaData("ID", SqlDbType.Int),
        new SqlMetaData("UserName", SqlDbType.VarChar),
        new SqlMetaData("UserPassword", SqlDbType.VarChar),
    });

    // start sending and tell the pipe to use the created record
    SqlContext.Pipe.SendResultsStart(rec);
    {
        // send items step by step
        foreach (User user in GetUsers())
        {
            int id = user.ID;
            string userName = user.UserName;
            string userPassword = user.UserPassword;

            // set values
            rec.SetSqlInt32(0, id);
            rec.SetSqlString(1, userName);
            rec.SetSqlString(2, userPassword);

            // send new record/row
            SqlContext.Pipe.SendResultsRow(rec);
        }
    }
    SqlContext.Pipe.SendResultsEnd();    // finish sending
}