在Windows Phone 7 app dev中需要帮助..... [英] need help in windows phone 7 app dev.....

查看:91
本文介绍了在Windows Phone 7 app dev中需要帮助.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里,

我对这个所谓的"windows phone 7"都很陌生。应用程序 开发

i m all new to this so called "windows phone 7" application development

我正在开发一个多语言。字典应用程序

i m developing an a multi lang. dictionary app

nm在使用数据库时遇到问题(隔离存储)

n m facing problems in working with the database(isolated storage)

我的应用程序的工作如下:

working of my app is as follows:

一个菜单页面

有四个菜单按钮,用于四个不同的词典

having four menu buttons for four diff lang dictionaries

每个按钮导航到一个新页面(对应于该页面) la diction。(4页))

each button navigates to a new page (corresponding to that lang diction.(4 pages))

每个词典。将拥有自己的数据库

each dict. will have its own database

界面就像(两个文本框  {1。用于搜索单词,其他用于搜索结果和一个搜索按钮})

interface is like(two text boxes {1. for word to be searched and other for result and a button to search})

将在数据库中搜索第一个文本框中的字符串,如果找到,则相应的含义将显示在另一个文本框中

the string from the first text box will be searched in the db and if found then corresponding meaning will be displayed on the other textbox

..... im使用以下代码:

.....i m using the following codes:

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Net ;

使用System.Windows;

使用System.Windows.Controls;

使用System.Windows.Documents;

使用System.Windows.Input;

使用System.Windows.Media;

使用System.Windows.Media.Animation;

使用System.Windows.Shapes;

使用Microsoft.Phone.Controls;

使用System.Windows.Ink;

使用System.Data.Linq .Mapping;

使用System.Data.Linq;

 使用System.Resources;

使用System.Data.Services;

使用PhoneApp6.ServiceReference1;

使用System.Collections.ObjectModel;

使用System.ComponentModel;

使用System。 IO.IsolatedStorage;

使用System.Linq.Expressions;

使用System.Text.RegularExpressions;

使用System.Text;

使用System.Xml.Serialization;

使用System.IO;

使用System.Runtime;

命名空间PhoneApp6

{

    public partial class Page4:PhoneApplicationPage



    {public const string ConnectionString = @" isostore:/engSansDB.sdf" ;;

       公共Page4()

        {InitializeComponent();

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 Microsoft.Phone.Controls;
using System.Windows.Ink;
using System.Data.Linq.Mapping;
using System.Data.Linq;
 using System.Resources;
using System.Data.Services;
using PhoneApp6.ServiceReference1;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO.IsolatedStorage;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Runtime;
namespace PhoneApp6
{
    public partial class Page4 : PhoneApplicationPage

    {public const string ConnectionString = @"isostore:/engSansDB.sdf";
        public Page4()
        { InitializeComponent();

 }



[表(Name =" engsansdict")]

       公共课程engSans

        {

            [Column(IsPrimaryKey = true,IsDbGenerated = true,CanBeNull = false,AutoSync = AutoSync.OnInsert)]¥b $ b           公共字符串英文

            {get;组; }¥b $ b    [栏目(CanBeNull = false)]
$


$
    public string sans

            {get;组; }¥b $ b        }


        public class engSansDataContext:DataContext

        {public engSansDataContext(string connectionString)

            :base(connectionString)

        {}

  &NBSP; &NBSP; &NBSP; public Table< engSans> englishsans {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;得到{return this.GetTable< engSans>();}

  &NBSP; &NBSP; &NBSP; } 

  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; private void addData()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; using(engSansDataContext context = new engSansDataContext(ConnectionString))

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; engSans obj = new engSans();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; obj.english =" cow"; $
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.englishsans.InsertOnSubmit(obj);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; engSans obj1 = new engSans();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; obj.sans =" gau";

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.englishsans.InsertOnSubmit(obj);
$


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.SubmitChanges();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; } 

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP;   public IList< engSans> getengSansList()

  &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;的IList< engSans> elist = null;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; using(engSansDataContext context = new engSansDataContext(ConnectionString))

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IQueryable的< engSans> query = from sans in context.englishsans select sans;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; elist = query.ToList();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; } return elist;



  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP;   public void createDB()

  &NBSP; &NBSP;   {

  &NBSP; &NBSP; &NBSP; &NBSP;   using(engSansDataContext context = new engSansDataContext(ConnectionString))

  &NBSP; &NBSP; &NBSP; &NBSP;   {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   if(context.DatabaseExists()== false)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   {
$


$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   //创建数据库(如果不存在)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   context.englishsans.Context.CreateDatabase();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   MessageBox.Show("成功创建员工数据库!!!");

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  }

  &NBSP; &NBSP; &NBSP; &NBSP;  }

  &NBSP; &NBSP;  }

  &NBSP; &NBSP;   private void button1_Click(object sender,RoutedEventArgs e)

  &NBSP; &NBSP;   {

$
  &NBSP; &NBSP; &NBSP; &NBSP;  试试
  &NBSP; &NBSP; &NBSP; &NBSP;   {  IList< engSans> elist = this.getengSansList();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;列表与LT; engSans> ob = new List< engSans>();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   engSans ob1 = new engSans();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   textBox3.Text = ob1.sans;

  &NBSP; &NBSP; &NBSP; &NBSP;  }

  &NBSP; &NBSP; &NBSP; &NBSP;   catch {} 



$


  &NBSP; &NBSP;  }
$


  &NBSP; &NBSP; &NBSP; private void textBox1_TextChanged(object sender,TextChangedEventArgs e)

  &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; private void textBox3_TextChanged(object sender,TextChangedEventArgs e)

  &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; private void textBox2_TextChanged(object sender,TextChangedEventArgs e)

  &NBSP; &NBSP; &NBSP; {

$
  &NBSP; &NBSP; &NBSP; }




  &NBSP; }¥b $ b}   &NBSP;   

 }

[Table(Name= "engsansdict")]
        public class engSans
        {
            [Column(IsPrimaryKey = true, IsDbGenerated = true, CanBeNull = false, AutoSync = AutoSync.OnInsert)]
            public string english
            { get; set; }
    [Column(CanBeNull = false)]


    public string sans
            { get; set; }
        }

        public class engSansDataContext : DataContext
        { public engSansDataContext(string connectionString)
            :base(connectionString)
        {}
        public Table<engSans>englishsans{
            get{return this.GetTable<engSans>();}
        } 
        }

        private void addData()
        {
            using (engSansDataContext context = new engSansDataContext(ConnectionString))
            {
                engSans obj = new engSans();
                obj.english = "cow";
                context.englishsans.InsertOnSubmit(obj);
                engSans obj1 = new engSans();
                obj.sans = "gau";
                context.englishsans.InsertOnSubmit(obj);

                context.SubmitChanges();
            } 
        }
       public IList<engSans>getengSansList()
        {
            IList<engSans> elist = null;
            using (engSansDataContext context = new engSansDataContext(ConnectionString))
            {
                IQueryable<engSans> query = from sans in context.englishsans select sans;
                elist = query.ToList();
            } return elist;

        }

       public void createDB()
       {
           using (engSansDataContext context = new engSansDataContext(ConnectionString))
           {
               if (context.DatabaseExists() == false)
               {


                   // create database if it does not exist
                   context.englishsans.Context.CreateDatabase();

                   MessageBox.Show("Employee Database Created Successfully!!!");
               }
           }
       }
       private void button1_Click(object sender, RoutedEventArgs e)
       {

           try
           { IList<engSans> elist = this.getengSansList();
               List<engSans> ob = new List<engSans>();
               engSans ob1 = new engSans();
               textBox3.Text = ob1.sans;
           }
           catch { }  



       }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
        {

        }


    }
}      

但它不起作用....按钮是做"没事"...请帮助我....请......如果我在button_click func中删除异常。然后点击按钮就会发出运行时错误..未处理的异常..."未定义db的路径"
或"db不存在"类似的东西,并显示绿色标记..."elist.query = tolist();"

but its not working....the button is doing "nothing"...pls help me ....please......if i remove the exception in button_click func. then at the click of the button it gives a runtime error ..unhandled exception..."db's path is not defined" or"db doesn't exist" something like that and shows a green mark over..."elist.query=tolist();"

推荐答案

嗨nikzz ,

Hi nikzz,

engSansDB.sdf ?你一定非常。您的应用找不到您的
数据库。当你打电话给 
createDB()方法?

engSansDB.sdf exists in your isolatedstorage at runtime? You must very that. You app doesn't find your DB. When you call to createDB() method?

问候。


这篇关于在Windows Phone 7 app dev中需要帮助.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆