I was configuring one of my form where I was adding the button to find the one when I indicated an ID I would upload the patient data to all my texbox, when making the code and when executing it, everything was fine until the moment when I wanted to save The data of my appointment form I get the following, I would like to help me and tell me that this error comes.
error you have an error in your sql syntax check the manual that corresponds to your mysql server version for the syntax to use near ') at Line 1
This is my Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Consultorio_Clinico
{
public partial class Citas : Form
{
public Citas()
{
InitializeComponent();
}
MySqlConnection conectar = new MySqlConnection("server=localHost;DataBase=consulta_clinica;Uid=1234;pwd=polo123;");
MySqlCommand comando;
MySqlDataReader mdr;
private void button7_Click(object sender, EventArgs e)
{
{
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
conectar.Open();
string selectQuery = "select * from paciente where id_pacient=" + int.Parse(txtbuscarnom.Text);
comando = new MySqlCommand(selectQuery, conectar);
mdr = comando.ExecuteReader();
if (mdr.Read())
{
txtidpacient.Text = mdr.GetString("id_pacient");
txtnompacient.Text = mdr.GetString("nom_pacient");
txtedapacient.Text = mdr.GetInt32("ed_pacient").ToString();
txttelpacient.Text = mdr.GetString("tel_pacient");
txtdirpacient.Text = mdr.GetString("dir_pacient");
txtciudpacient.Text = mdr.GetString("ciud_pacient");
}
else
{
MessageBox.Show("No existen datos para esta ID");
}
conectar.Close();
txtbuscarnom.Clear();
}
private void btnbuscardoct_Click(object sender, EventArgs e)
{
conectar.Open();
string selectQuery = "select * from medico where id_doct=" + int.Parse(txtbuscardoct.Text);
comando = new MySqlCommand(selectQuery, conectar);
mdr = comando.ExecuteReader();
if (mdr.Read())
{
txtiddoct.Text = mdr.GetString("id_doct");
txtnomdoct.Text = mdr.GetString("nom_doct");
txtespecdoct.Text = mdr.GetString ("espec_doct");
}
else
{
MessageBox.Show("No existen datos para esta ID");
}
conectar.Close();
txtbuscardoct.Clear();
}
private void txtbuscarnom_TextChanged(object sender, EventArgs e)
{
}
private void btnguardar_Click(object sender, EventArgs e)
{
try
{
conectar.Open();
MySqlCommand comando = new MySqlCommand("insert into cita values('" + txtidpacient.Text + "','" + txtnompacient.Text + "','" + txtedapacient.Text + "','" + txttelpacient.Text + "','" + txtdirpacient.Text + "','" + txtciudpacient.Text + "','" + dateTimefecha.Text + "','" + txtprecpacient.Text + "','" + txtiddoct.Text + "','" + txtnomdoct.Text + "','" + txtespecdoct.Text + "',)", conectar);
comando.ExecuteReader();
MessageBox.Show("Registro guardado con exito");
}
catch (Exception error)
{
MessageBox.Show("Error.." + error.Message);
}
conectar.Close();
txtidpacient.Clear();
txtnompacient.Clear();
txtedapacient.Clear();
txttelpacient.Clear();
txtdirpacient.Clear();
txtciudpacient.Clear();
txtprecpacient.Clear();
txtiddoct.Clear();
txtnomdoct.Clear();
txtespecdoct.Clear();
txtbuscarnom.Clear();
txtbuscardoct.Clear();
}
}
}