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;
}
}
看在你的bin/debug文件夾爲數據庫文件的副本 – ErikEJ
這是問題。我甚至沒想過要去那裏看!感謝您的快速回復=) – user3309010