I am new in the world of programming; This semester the professor has put us a project in C#
, managing the database in Access
(I use the Access 16, since I have the license of it).
The problem is that when I save the data of one of the students in the database, I receive a Visual error informing me that the SQL statement has an error of sentaxis.
This is the error:
Unhandled exception of type 'System.Data.OleDb.OleDbException' in System.Data.dll
Additional information:
Syntax error in the INSERT INTO statement.
This is the code of the function:
public bool Agregar_Estudiantes(string Codigo, string Apellidos, string Nombres, string Edad, string Direccion, string Correo, string Sexo, string Tel_Res, string Tel_Movil, string Curso, string Mensualidad)
{
int Eda = Convert.ToInt32(Edad);
//Conexion
OleDbConnection Conexion = new OleDbConnection();
Conexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = D:\Proyecto Final POO\Proyecto Final POO\Proyecto Final POO.mdb; Persist Security Info = false;";
//Instruccion SQL
string CadenaSQL = "INSERT INTO Personal (Id, Apellidos, Nombres, Edad, Direccion, Correo, Sexo, Tel_Res, Tel_Movil, Curso, Mensualidad) ";
CadenaSQL = CadenaSQL + " VALUES ( " + Codigo + ",";
CadenaSQL = CadenaSQL + " '" + Apellidos + "',";
CadenaSQL = CadenaSQL + " '" + Nombres + "',";
CadenaSQL = CadenaSQL + " " + Eda + ",";
CadenaSQL = CadenaSQL + " '" + Direccion + "',";
CadenaSQL = CadenaSQL + " '" + Correo + "',";
CadenaSQL = CadenaSQL + " '" + Sexo + "',";
CadenaSQL = CadenaSQL + " '" + Tel_Res + "',";
CadenaSQL = CadenaSQL + " '" + Tel_Movil + "',";
CadenaSQL = CadenaSQL + " '" + Curso + "',";
CadenaSQL = CadenaSQL + " '" + Mensualidad + "')";
//Crear comando
OleDbCommand Comando = Conexion.CreateCommand();
Comando.CommandText = CadenaSQL;
//Ejecutar la consulta de accion
Conexion.Open();
Comando.ExecuteNonQuery();
Conexion.Close();
return true;
}
The data is received in a TexBox
, and sent from a Button
, who assigns the values to the function that I have shown above.
Thanks for your help!