Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am building an application on C# using SQLite, I get an error, couldn't fix it, I am a beginner in C# this is the

I am building an application on C# using SQLite, I get an error, couldn't fix it, I am a beginner in C#

this is the code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Diagnostics;

using SQLite;

using Xamarin.Forms;

namespace FormsMenu

{

public class ContactListDB

{

private SQLiteConnection _connection;

public ContactListDB()

{

_connection = DependencyService.Get().GetConnection();

_connection.CreateTable();

Debug.WriteLine("Connection String: " + _connection.ToString());

}

public IEnumerable GetTheContact()

{

return _connection.Query("SELECT * FROM Contacts ORDER BY LastName, FirstName");

}

public int Count()

{

return Convert.ToInt32(_connection.Table().Count());

}

public Contact GetTheContact(int id)

{

return _connection.Table().FirstOrDefault(t => t.ID == id);

}

public void AddContact(string fName, string lName, string type)

{

var newContact = new Contact(fName, lName, type);

string updateTheQuery = string.Format("INSERT INTO Contacts (FirstName, LastName, ContactType, FullName) VALUES ('{0}', '{1}', '{2}'. '{3}'", newContact.FirstName, newContact.LastName, newContact.ContactType, newContact.FullName);

_connection.Execute(updateTheQuery);

}

public void DeleteContact(int id)

{

_connection.Delete(id);

}

public void updateContact(string fName, string lName, string type, int id)

{

string updateTheQuery = string.Format("UPDATE Contacts SET FirstName='{0}', LastName='{1}', ContactType='{2}', FullName='{0} {1}' WHERE ID={3}", fName, lName, type, id);

_connection.Execute(updateTheQuery);

}

}

}

image text in transcribedimage text in transcribed

using System; using System.Collections.Generic; using System.Linq; using System. Text; 1 2 4 5 using System.Threading.Tasks; using System.Diagnostic using SQLite; using Xamarin.Forms; 9 namespace FormsMenu 12 public class ContactListDB private SQLiteConnection _connection; public ContactListDB() 17 connection DependencyService . Get ISQLite>().GetConnection(); connection. CreateTable(); Debug.WriteLine("Connection String: connection.ToString()); 21 public IEnumerable("SELECT FROM Contacts ORDER BY LastName, FirstName"); 26 27 public int Count() return Convert.ToInt32(_connection.Table().Count 30 31 32 public Contact GetTheContact(int id) 34 35 36 37 38 39 40 41 Exception Unhandled return -connection . Table().F Unhandled Exception: public void AddContact(string fName, stri SQLite.SQLiteException: near "Joe Abbott" syntax error Copy Details var newContact = new Contact(fName, 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started