WPF 查询表格数据

WPF 三层架构 客户端请求数据传递到服务端,服务端再到数据库里操作数据库,然后返回给服务端,服务端再返回给客户端,就可以查询出数据了

首先在数据库新建存储过程

代码:

IF(@type='UserControl_Loaded_SelectStaffAccountManage')

--查询表格数据

--RTRIM 右去空格

--BEGIN 开始语句

--END 结束语句

--AS 重命名

--INNER JOIN  ON 连接表格

--ORDER BY 排序   DESC 倒叙排序

  BEGIN

        SELECT ROW_NUMBER()over(order by t_operators.operator_id) as number,

         t_operators.operator_id,   t_operators.staff_id,

             RTRIM(t_staff.staff_name)AS name,

             RTRIM(t_operators.operator_accounts) AS accounts,

             RTRIM(t_operators.operator_password )AS password,

             RTRIM( case WHEN t_operators.effective='true'  THEN '有效' ELSE '无效' END) AS effective,

             RTRIM(t_operators.note) AS note

        FROM      t_operators INNER JOIN

                t_staff ON t_operators.staff_id = t_staff.staff_id

                ORDER BY t_operators.operator_id DESC

  END

执行的结果:

WPF 查询表格数据

在服务器写连接数据库的代码

代码:

[ServiceContract]

   public class UC_StaffAccountManage

    {

        DAL.DALMethod myDALMethod = new DAL.DALMethod();

        //OperationContract(操作契约)

        [OperationContract]

        public DataSet UserControl_Loaded_SelectStaffAccountManage()

        {

            //1.0实例化对象数组(序列化参数)

            SqlParameter[] mySqlParameters =

            {

                new SqlParameter("@type",SqlDbType.NChar),

            };//BLL.SystemInformation.UC_StaffAccountManage.svc

            mySqlParameters[0].Value = "UserControl_Loaded_SelectStaffAccountManage";//获取执行的存储过程名称

            DataSet ds = myDALMethod.QueryDataSet("UC_StaffAccountManage", mySqlParameters);

            return ds;

        }

}

客户端的代码:
    //实例化

        BLL.UC_StaffAccountManage.UC_StaffAccountManageClient myClient = new BLL.UC_StaffAccountManage.UC_StaffAccountManageClient();

 

        //绑定表格数据

        private void SelectdgAccountManage()

        {

            //执行方法返回数据

            DataTable dt = myClient.UserControl_Loaded_SelectStaffAccountManage().Tables[0];

            //绑定表格数据

            dgAccountManage.ItemsSource = dt.DefaultView;

        }

页面的代码的字段要和数据库字段相对应就可以绑定表格数据了

效果:WPF 查询表格数据