首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将在数据访问层中创建的数据集绑定到UI中的网格视图?

如何将在数据访问层中创建的数据集绑定到UI中的网格视图?
EN

Stack Overflow用户
提问于 2012-09-26 01:09:32
回答 3查看 1.1K关注 0票数 0

下面是代码..

代码语言:javascript
运行
复制
namespace ConfigurationSystem.DataAccess
{
    public class DataAccessLayer
    {
        public DataSet GetRoleCreationDetails(int? Roles_Id, string Code, string Name, string IsActive)
        {

            try
            {
                string con = @"Data Source=PAVANKUMAR-PC\PAVAN;Initial Catalog=ConfigurationSystem;Integrated Security=True";
                SqlConnection connection = new SqlConnection(con);
                SqlCommand command = new SqlCommand();
                command.Connection = connection;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "SP_GetRoleCreationDetails";
                command.Parameters.AddWithValue("@UserRole_Id", Roles_Id);
                command.Parameters.AddWithValue("@RoleId", Code);
                command.Parameters.AddWithValue("@UserId", Name);
                command.Parameters.AddWithValue("@IsActive", IsActive);

                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataSet dataset = new DataSet();
                adapter.Fill(dataset);
                //status = Convert.ToString(command.Parameters["@OuptputParam"].Value);
                return dataset;
            }
            catch (Exception exception)
            {
                throw new ArgumentException(exception.Message);
            }
        }
    }
}
EN

回答 3

Stack Overflow用户

发布于 2012-09-26 01:10:43

将数据集传递给UI并执行以下操作:

代码语言:javascript
运行
复制
myGrid.DataSource = GetReturnedDS();
myGrid.DataBind();

换句话说,在UI中:

代码语言:javascript
运行
复制
Dataset ds = MyBLL.GetData();
myGrid.DataSource = ds;
myGrid.DataBind();

在BLL中:

代码语言:javascript
运行
复制
public static DataSet GetData()
 {
  return  DLL.GetData();
 }

在DLL中:

代码语言:javascript
运行
复制
public static DataSet GetData()
 {
  //your code here
  return yourDataSet;
 }
票数 1
EN

Stack Overflow用户

发布于 2012-09-26 01:12:34

您需要先创建class DataAccessLayer的object。可以在表单顶部使用,也可以在类名前加上命名空间,如下所示。您需要为您的类和命名空间使用有意义的全名。

代码语言:javascript
运行
复制
grid1.DataSource = new ConfigurationSystem.DataAccess.DataAccessLayer().GetRoleCreationDetails("1", "code", "name", "true");
grid1.DataBind();
票数 0
EN

Stack Overflow用户

发布于 2012-09-26 01:12:40

在您的aspx.cs中执行此操作

代码语言:javascript
运行
复制
myGrid.DataSource = new DataAccessLayer().DataGetRoleCreationDetails(parameters here..)
myGrid.DataBind();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12587829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档