I tried creating a database that would store the answers of users but I keep getting this error System.NullReferenceException: 'Object reference not set to an instance of an object.'
public class MySQLDatabase
{
private SQLiteConnection conn;
public void MyDatabase()
{
conn = new SQLiteConnection("mydatabase.db3");
conn.CreateTable<MyTable>();
}
public void InsertData(int gameid, string preorder,string rating,string standards,string overpriced,string agerating,string gameplay,string recommend,string impact)
{
MyTable myNewTable = new MyTable
{
GameId = gameid,
PreOrder = preorder,
Rating = rating,
Standards = standards,
OverPriced = overpriced,
AgeRating = agerating,
Gameplay = gameplay,
Recommend = recommend,
Impact = impact
};
conn.Insert(myNewTable);
}
public void CloseConnection()
{
conn.Close();
}
}
}
This is where i initialize it
private void Button_Pressed(object sender, EventArgs e)
{
MySQLDatabase db = new MySQLDatabase();
string q1 = Question1.ToString();
string q2 = Question2.ToString();
string q3 = Question3.ToString();
string q4 = Question4.ToString();
string q5 = Question5.ToString();
string q6 = Question6.ToString();
string q7 = Question7.ToString();
string q8 = Question8.ToString();
db.InsertData(5, q1, q8, q4, q3, q5, q6, q7, q2);
db.CloseConnection();
}
It seems that the table that i am trying to add to the database isn't getting populated or that's what i am getting from it.