Look in your bin/debug folder, I think you will find a copy of your database file there with the expected data
Database (SDF) returning less than actual max rows
-
11-10-2022 - |
Question
The issue that I am having is that I have 12 rows in my SQL Server Compact database (.sdf
).
However, when pulling the data to my list of custom objects, it only contains the first three objects from the database.
Is there a specific or even vague reason why I am not getting the full return of rows from my database? During debugging, it looks as if maxRows
is also saying the database only has three rows.
Also, when trying to increase maxRows
by 1 in code, an error returns that the database does not contain more than three rows.
I have tried this, repairing the database, rebuilding the database. The only route I have not taken is creating a brand new project, with a brand new database.
Edit
For clarification, this is a windows form project, and I am sending the Recipe.Name
to a combobox on my form.
Here is my code:
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;
}
}
Solution