| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:代码有误求解
只看楼主 加入收藏
顾帆
Rank: 1
等 级:新手上路
帖 子:10
专家分:2
注 册:2011-11-12
结帖率:60%
收藏
已结贴  问题点数:10 回复次数:1 
代码有误求解
using System;
using System.Collections.Generic;
using System.Linq;
using
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 SL_31102017.Web;
namespace SL_31102017
{
    public partial class MainPage : UserControl
    {
        
       DomainService1 m_ds =null;

        public MainPage()
        {
               InitializeComponent();
               m_ds.Load(m_ds.GetStudentsQuery());
               m_ds = new DomainService1();
               m_ds.Load(m_ds.GetStudentsQuery());
              dg_装载数据.ItemsSource = m_ds.students;
         
        }

        private void bt_增加_Click(object sender, RoutedEventArgs e)
        {

            student sd = new student();
            sd.编号 = Convert.ToInt32(tb_编号.Text);
            sd.出勤期 = Convert.ToDateTime(tb_出勤期.Text);
            sd.年龄 = Convert.ToInt32(tb_年龄.Text);
            sd.姓名 = Convert.ToString(tb_姓名);
            m_ds.students.Add(sd);
            m_ds.SubmitChanges();
            if (rb_男.IsChecked == true)
            {
                sd.性别 = Convert.ToBoolean("true");
            }
            else
            {
                sd.性别 = Convert.ToBoolean("false");
            }
            if (tb_编号.Text == "" && tb_出勤期.Text == "" && tb_年龄.Text == "" && tb_姓名.Text == "")
            {

                MessageBox.Show("您未添加任何数据!");

            }
         
        }

        private void bt_修改_Click(object sender, RoutedEventArgs e)
        {

            student sd =(student)dg_装载数据.SelectedItem;
            sd.编号 = Convert.ToInt32(tb_编号.Text);
            sd.出勤期 = Convert.ToDateTime(tb_出勤期.Text);
            sd.年龄 = Convert.ToInt32(tb_年龄.Text);
            sd.姓名 = Convert.ToString(tb_姓名);
            m_ds.SubmitChanges();

        }

        private void bt_删除_Click(object sender, RoutedEventArgs e)
        {

            student sd = (student)dg_装载数据.SelectedItem;
            m_ds.students.Remove(sd);
            m_ds.SubmitChanges();
        }

        private void bt_退出_Click(object sender, RoutedEventArgs e)
        {
           
        }
    }
}   
这句代码有误
 m_ds.Load(m_ds.GetStudentsQuery());(未能将对象引用到对象实例)


搜索更多相关主题的帖子: class public null 
2011-12-18 10:47
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:10 
public MainPage()
{
     InitializeComponent();
     //m_ds.Load(m_ds.GetStudentsQuery());
     m_ds = new DomainService1();
     m_ds.Load(m_ds.GetStudentsQuery());
     dg_装载数据.ItemsSource = m_ds.students;
}
m_ds定义为null,当然要先实例化才能使用,所以在new之前就不要使用
2011-12-19 21:58
快速回复:代码有误求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046690 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved