Reputation: 1543
I have this piece of code from one of my classes and when i hover over the semicolon next to "//error is here" "} Expected" but all the brackets are closed, i have no idea why its causing this, i tried rebuilding but nothing changes
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SQLite.Net;
using SQLite.Net.Platform.WinRT;
namespace HomeAutomation
{
public class MainCode
{
static string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
static SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), path)
{
conn.CreateTable<User>;//ERROR IS HERE
}
}
public class User
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Upvotes: 0
Views: 1416
Reputation: 583
I think what you've done here to use the keyword static
when you should have used using
Looking at what you're trying to achieve I'd suggest your code might need to look something like:
using SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), path)
{
conn.CreateTable<User>();//ERROR IS HERE
}
What have I changed?
I've changed the word static
to using
and added the brackets to the end of the conn.CreateTable<User>()
Hope this helps!
Upvotes: 0
Reputation: 165
Not sure if this will help but maybe try:
conn.CreateTable<User>("SELECT somethingHere FROM somewhere");
Upvotes: 0
Reputation: 953
You're using an object initiationalization. You don't use semi-colon in it b/c a semi-colon indicates the termination point of a command. You're not allowed to end a statement in the middle of initialization. You would separate each field you're initializing with a comma and then end the statement after the last curly brace.
Edit
It looks like you shouldn't be using object initialization after looking at the code again. This syntax is for initializing property on objects. You need to separate the two statments. I.e.
static SQLiteConnection conn = new SQLiteConnection(new SQLitePlatformWinRT(), path); // End initialization statement
static MainCode()
{
conn.CreateTable<User>;//Initialize in static constructor
}
Upvotes: 4
Reputation: 2530
This conn.CreateTable<User>;//ERROR IS HERE
should read
conn.CreateTable<User>();//solved
You forgot the brackets
Upvotes: 1