这是一个新手问题,我正在尝试在 C# 中构建一个UserOrgs
将为用户设置属性的类(每个用户可以有多个)
到目前为止,我有这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for clsRepUser
/// </summary>
public class clsUser
{
private string userid;
private List<string> userorgs;
public string UserID
{
get
{
return userid;
}
set
{
userid = value;
}
}
public List<string> UserOrgs
{
get
{
return userorgs;
}
set
{
userorgs = value;
}
}
clsConn cCon = new clsConn();
String connStr = "";
public clsUser()
{
}
public DataSet GetUserOrg(string UserID)
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(cCon.getConn());
SqlCommand cmd = new SqlCommand("sp_getUserOrgs", conn);
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(
new SqlParameter("@UserID", UserID));
try
{
// Open the connection and execute the Command
conn.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = cmd;
sqlDA.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
return ds;
}
}
我现在如何UserOrgs
从函数中填充该用户的属性GetUserOrg
?或者我在这方面做得不够好?