1

I have C# project for Windows Phone 8.1 with SQLite database.
Database contain a table, from which need select all data, and write it into array. Also have 2 classes: Links (like name of table) - contain description of table; Repository - class for methods.
I dont know how create method for inserting. Begin like: using (var statement = SQLiteConnection.Prepare("SELECT _id, link FROM links WHERE _id=?")), but what next?

3
  • Which wrapper are you using? Commented Jun 19, 2015 at 13:15
  • Sorry, I dont understand what it is Commented Jun 19, 2015 at 13:30
  • On Windows Phone you would normally use SQLite with a wrapper as some sort of abstraction layer: github.com/koush/sqlite-net / nuget.org/packages/SQLite.Net-PCL. Commented Jun 19, 2015 at 15:01

1 Answer 1

1

It's so simple.
Use class for description table (Linkes) to create new array(type). In other class create List method with query what you need.

public  List <Linkses> Gettha()
        {
            List<Linkses> lin = new List<Linkses>();
            using (var statement = con.Prepare("SELECT _id, link FROM links"))
            {
                 while (statement.Step() == SQLiteResult.ROW)
                 {
                     Linkses link = new Linkses();
                     link.Id = (long)statement[0];
                     link.Linochka = (string)statement[1];
                     lin.Add(link);
                    }
            }
            return lin;
        }

Then you must call that method with ToArray.

Linkses[] holla = App.repo.Gettha().ToArray();
Sign up to request clarification or add additional context in comments.

1 Comment

You will possibly get error if you try to type cast a statement object to a long in this way: link.Id = (long)statement[0]; Rather use this way: Long.parseLong(statement[0].ToString())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.