C# 数据库(SDF)返回的行数小于实际最大行数

C# 数据库(SDF)返回的行数小于实际最大行数,c#,database,sql-server-ce,C#,Database,Sql Server Ce,我遇到的问题是,我的SQL Server Compact数据库中有12行(.sdf) 但是,当将数据拉入自定义对象列表时,它只包含数据库中的前三个对象 是否有一个具体的甚至模糊的原因,为什么我不能从我的数据库中得到完整的行返回?在调试期间,似乎maxRows也表示数据库只有三行 另外,当试图在代码中将maxRows增加1时,会返回一个错误,即数据库包含的行不超过三行 我尝试过这个,修复数据库,重建数据库。我唯一没有采取的方法是创建一个全新的项目,使用一个全新的数据库 编辑 为了澄清,这是一个wi

我遇到的问题是,我的SQL Server Compact数据库中有12行(
.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;
        }
    }
2
{
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
公共部分类Form1:Form
{
专用数据库连接对象连接;
私有字符串构造;
私有数据集ds;
私人数据行卓尔;
私有int-maxRows;
私人静态国际公司;
私有列表myRecipes=新列表();
公共表格1()
{
this.InitializeComponent();
}
私有void Form1Load(对象发送方、事件参数e)
{
尝试
{
this.objConnect=新数据库连接();
this.consting=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)
{
这个.NavigateRecords();
Inc++;
}
}
捕获(异常错误)
{
MessageBox.Show(错误消息);
}
foreach(此.myRecipes中的Recipe rec)
{
this.comboBoxLevelSelect.Items.Add(rec.Name);
}
}
专用void导航记录()
{
this.dRow=this.ds.Tables[0]。行[Inc];
字符串le=this.dRow.ItemArray.GetValue(0.ToString();
字符串na=this.dRow.ItemArray.GetValue(1.ToString();
string ing=this.dRow.ItemArray.GetValue(2.ToString();
string ef=this.dRow.ItemArray.GetValue(3.ToString();
字符串ob=this.dRow.ItemArray.GetValue(4.ToString();
这个是.myRecipes.Add(
新配方(le、na、ing、ef、ob);
}
公共课食谱
{
公共字符串级别{get;set;}
公共字符串名称{get;set;}
公共字符串{get;set;}
公共字符串效果{get;set;}
公共字符串获取{get;set;}
公共配方(字符串级别、字符串名称、,
字符串成分、字符串效果、字符串获取)
{
这个。级别=级别;
this.Name=Name;
这个。成分=成分;
这个。效果=效果;
这个。获得=获得;
}
}

在您的bin/debug文件夹中查找,我想您会在那里找到一份包含预期数据的数据库文件副本

在您的bin/debug文件夹中查找问题所在的数据库文件副本。我甚至没有想到要查看那里!感谢您的快速回复=)