실버라이트 초간단 데이터 바인딩

1.ADO.NET Entity Data Model 을 만듭니다 (서버측)

image

2. 그런다음 데이터베이스에 접근할수 있는 ado.net Data Service 를 만들어줍니다. (서버측)

image

만들어진 Ado.Net Data Service

image

3.실버라이트 프로젝트에서 웹서비스를 참조합니다.

image

4.데이터그리드에 데이터를 바인딩 합니다.

아래는 간단한 소스

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Data.Services.Client;
using System.Collections.ObjectModel;
using System.ComponentModel;
using BM.ServiceReference1;
namespace BM.CodeTest
{
    public partial class Delete : UserControl
    {
        ServiceReference1.TEST_BOOKEntities svcContext;
        ObservableCollection<ServiceReference1.BOOK> ObsvBookCollrection;
        BooksDS bookDs;


        public Delete()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Delete_Loaded);
        }

        void Delete_Loaded(object sender, RoutedEventArgs e)
        {

            svcContext = new TEST_BOOKEntities(new Uri("BookWebDataService.svc", UriKind.Relative));
            ObsvBookCollrection = new ObservableCollection<BOOK>();
            bookDs = new BooksDS();
            DataServiceQuery<BOOK> query = (DataServiceQuery<BOOK>)
                (from c in svcContext.BOOK select c);
            query.BeginExecute(GetDataCallback, query);

        }

 

        #region 셀렉트

        void GetDataCallback(IAsyncResult result)
        {

            try
            {
                DataServiceQuery<BOOK> queryResult =
                               (DataServiceQuery<BOOK>)result.AsyncState;

                IEnumerable<BOOK> results =
                              queryResult.EndExecute(result);

                foreach (var item in results)
                {
                    bookDs.Add(item);
                }
                    grdList.ItemsSource = bookDs;
   
              
                

                MessageBox.Show("도서목록가져오기 완료");

            }
            catch (DataServiceRequestException ex)
            {

            }


        }
        #endregion


    }
}


5.테스트 끝~

+ Recent posts