Hi Jason,
Thanks for the reply. Below is the code that I'm using (based on the Data
Access example from the Xamarin galleries). I guess the main reason I'm
struggling with this is that all of the examples I've found for using
SQLite-Net create the database and the table used programmatically. I
haven't found or seen a simple example using SQLite-Net to read data from a
pre-existing table in a pre-existing database. Now, it seems like it should
be straightforward of course, and it seems like this code should work, but
obviously there's something I'm just not grokking. Thanks for taking the
time to look!
==code below==========================================
namespace CountyDataAccess
{
public class HomeNavController : UITableViewController
{
protected List<CountyInfo> counties = new List<CountyInfo> ();
protected TableSource tableSource;
CountyInfo county;
string dbName = "SaleSites_v1_2.sqlite";
public HomeNavController () //: base(UITableViewStyle.Grouped)
{
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
// hide the nav bar when this controller appears
NavigationController.SetNavigationBarHidden (true,
true);
}
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
// show the nav bar when other controllers appear
NavigationController.SetNavigationBarHidden (false,
true);
}
public override void ViewDidLoad ()
{
var connection = new
SQLiteConnection(GetDBPath(dbName));
var countiesTable = connection.Table<CountyInfo>();
var counties = (from i in countiesTable select
i).ToList (); // using
System.Linq
tableSource = new TableSource (counties);
TableView = new UITableView () {
Source = tableSource
} ;
connection.Close ();
}
// The following also from BasicOperations.cs
protected string GetDBPath (string dbName)
{
// get a reference to the documents folder
var documents = Environment.GetFolderPath
(Environment.SpecialFolder.Personal);
// create the db path
string db = Path.Combine (documents, dbName);
return db;
}
// A simple data source for our table -- took this from
BasicOperations.cs
protected class TableSource : UITableViewSource
{
List<CountyInfo> items;
public TableSource (List<CountyInfo> items) : base() {
this.items =
items; }
public override int NumberOfSections (UITableView
tableView) { return 1;
}
public override int RowsInSection (UITableView
tableview, int section) {
return this.items.Count; }
public override UITableViewCell GetCell (UITableView
tableView,
NSIndexPath indexPath)
{
UITableViewCell cell;
cell = tableView.DequeueReusableCell ("item");
if(cell == null)
cell = new
UITableViewCell(UITableViewCellStyle.Default, "item");
cell.TextLabel.Text =
this.items[indexPath.Row].County + "County, " +
this.items[indexPath.Row].CountySeat;
return cell;
}
}
}
}
=== Also, here's the code for the CountyInfo class (from CountyInfo.cs)
=================
namespace CountyDataAccess
{
public class CountyInfo
{
public CountyInfo ()
{
}
public int ID { get; set; }
public string County { get; set; }
public string CountySeat { get; set; }
public int ZipCode { get; set; }
public string StreetAdd { get; set; }
public string CountyWeb1 { get; set; }
}
}
jawbrey wrote
>
> sqlite_sequence is an internal table used to manage autoincrement columns
>
> http://www.sqlite.org/autoinc.html
>
> can you post a code sample showing your data access?
>
> On Sat, May 19, 2012 at 3:52 PM, Chris_M <kungfuchris99@> wrote:
>
>>
>> I'm building an app that needs to use a pre-existing SQLite database
>> already
>> populated with data. Right now I'm just working on reading the data and
>> displaying it in a UITableView. (I'm using SQLite-Net in my code, just
>> FYI.)
>>
>> I have created the database, and I created a table called "CountyInfo" in
>> the database, and I have imported all the relevant data. Everything looks
>> ship-shape.
>>
>> When I compile and test my code, it finds the database just fine, but for
>> some reason it's not seeing the "CountyInfo" table that's already in
>> there.
>> Instead, it creates a new, second table in the database called
>> "sqlite_sequence", which has one record with three fields: rowid (value:
>> 1),
>> name (value: CountyInfo), and seq (value: 254). (My original "CountyInfo"
>> table is still sitting there in the database with all its data intact.)
>> The
>> data from the original CountyInfo is not displayed in my table view,
>> presumably because the app isn't seeing or reading the table for some
>> reason.
>>
>> What in the world is going on?
>>
>> I can post the relevant code from my project if necessary, but does
>> anyone
>> know what is happening just based on the above information?
>
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/SQLite-database-confusion-code-not-reading-table-tp4646271p4646351.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch