2014-02-14 37 views
0

我遇到的问题是我的SQL Server Compact数据库中有12行(.sdf)。数据库(SDF)返回的实际最大行数小于

但是,将数据拉到自定义对象列表时,它只包含数据库中的前三个对象。

为什么我没有从我的数据库中获得行的完整返回,是否存在特定的甚至模糊的原因?在调试期间,看起来好像maxRows也表示数据库只有三行。

另外,当试图在代码中将maxRows增加1时,错误返回数据库不包含多于三行。

我试过这个,修复数据库,重建数据库。我没有采取的唯一途径是创建一个全新的项目,并带有一个全新的数据库。

编辑

为了澄清,这是一个Windows窗体项目,我送Recipe.Name我的窗体上的组合框。

这里是我的代码:

namespace Recipes2 
{ 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

public partial class Form1 : Form 
{ 
    private DatabaseConnection objConnect; 

    private string conString; 

    private DataSet ds; 

    private DataRow dRow; 

    private int maxRows; 

    private static int Inc; 

    private List<Recipe> myRecipes = new List<Recipe>(); 

    public Form1() 
    { 
     this.InitializeComponent(); 
    } 

    private void Form1Load(object sender, EventArgs e) 
    { 
     try 
     { 
      this.objConnect = new DatabaseConnection(); 
      this.conString = Properties.Settings.Default.RecipeConnectionString; 

      this.objConnect.connection_string = this.conString; 
      this.objConnect.Sql = Properties.Settings.Default.SQL; 

      this.ds = this.objConnect.GetConnection; 

      this.maxRows = this.ds.Tables[0].Rows.Count; 

      while (Inc != this.maxRows) 
      { 
       this.NavigateRecords(); 

       Inc++; 
      } 
     } 
     catch (Exception err) 
     { 
      MessageBox.Show(err.Message); 
     } 

     foreach (Recipe rec in this.myRecipes) 
     { 
      this.comboBoxLevelSelect.Items.Add(rec.Name); 
     } 
    } 

    private void NavigateRecords() 
    { 
     this.dRow = this.ds.Tables[0].Rows[Inc]; 

     string le = this.dRow.ItemArray.GetValue(0).ToString(); 
     string na = this.dRow.ItemArray.GetValue(1).ToString(); 
     string ing = this.dRow.ItemArray.GetValue(2).ToString(); 
     string ef = this.dRow.ItemArray.GetValue(3).ToString(); 
     string ob = this.dRow.ItemArray.GetValue(4).ToString(); 

     this.myRecipes.Add(
      new Recipe(le, na, ing, ef, ob)); 
    } 

    public class Recipe 
    { 
     public string Level { get; set; } 

     public string Name { get; set; } 

     public string Ingredients { get; set; } 

     public string Effects { get; set; } 

     public string Obtain { get; set; } 

     public Recipe(string level, string name, 
     string ingredients, string effects, string obtain) 
     { 
      this.Level = level; 

      this.Name = name; 

      this.Ingredients = ingredients; 

      this.Effects = effects; 

      this.Obtain = obtain; 
     } 
    } 
+0

看在你的bin/debug文件夹为数据库文件的副本 – ErikEJ

+0

这是问题。我甚至没想过要去那里看!感谢您的快速回复=) – user3309010

回答

0

看在你的bin/debug文件夹,我想你会发现你的数据库文件中,有一份和预期的数据

相关问题