Hello Everybody,
I’m currently working on my end of year project and I got stuck on a very trivial thing. When I’m trying to add a new user to a database (local) I keep getting “Syntax error in INSERT INTO statement" I don’t really see where is the problem so I really hope You could spot it for me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using Domain;
namespace Transport_Management_System_Tools
{
class sqlConnector
{
OleDbConnection connection;
OleDbCommand command;
public void connectToDatabase()
{
connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database.accdb;Persist Security Info=False");
command = connection.CreateCommand();
}
public sqlConnector()
{
connectToDatabase();
}
public void AddUser(Users User)
{
try
{
command.CommandText = "INSERT INTO Users (FirstName,LastName,DOB,UserName,PassWord,Administrator,Manager) VALUES ('" + User.FirstName + "','" + User.LastName + "','" + User.DOB + "','" + User.Username + "','" + User.Password + "','" + User.Administrator + "','" + User.Manager + "')";
command.CommandType = System.Data.CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
}
}