I have a error like this while adding data to SQL table
Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'id,Member Name,Contact No,Address,Reg.date)VALUES('12312','asdfgnm','zxcvbn','xc' at line 1
My code is like this:
public partial class frmhome : Form
{
public frmhome()
{
InitializeComponent();
}
//Create the instant variable
MySqlConnection mysqlConn;
MySqlDataAdapter mysqlAdapt;
MySqlDataReader mysqlRead;
MySqlCommand mysqlComm;
//Create the Memory Variable
String qry;
//add member
private void Home_Load(object sender, EventArgs e)
{
panelmemreg.Visible = true;
panelAddbook.Visible = false;
panelissue.Visible = false;
panelres.Visible = false;
//Using Error handler tool
try
{
//Create the Memory Variable
string srv, db, user, pass;
//Assigning the values
srv = "localhost"; db = "lms"; user = "root"; pass = "";
//assigning the command
qry = "SERVER=" + srv + ";" + "DATABASE=" + db + ";" + "UID=" + user + ";" + "PASSWORD=" + pass + ";";
mysqlConn = new MySqlConnection(qry);
}
catch (Exception ex)
{
//Display Error Message
MessageBox.Show("Couldn't connect :" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
//using the error handler tool
try
{
//Set the sql statement
qry = "INSERT INTO member (Member id,Member Name,Contact No,Address,Reg.date)VALUES('" + txtbid.Text + "','" + txtbname.Text + "','" + txtbtelno.Text + "','" + txtbaddr.Text + "','" + dtpreg.Value.Date + "')";
//Open the connection
mysqlConn.Open();
//Set the statement in command control
mysqlComm = new MySqlCommand(qry, mysqlConn);
//Execute the statement
mysqlComm.ExecuteNonQuery();
String msg3 = "Add new member Successfully";
lblStatus.Text = msg3;
}
finally
{
//close the connection
mysqlConn.Close();
}
}