How will I make this not prone to SQL injection? These codes are to insert data to database, and alot says that in this format it is prone to SQL injection.
private void DBConn()
{
string ConString = "datasource = localhost; Username = root; Password=; database = logbook";
MySqlConnection DBConnnect = new MySqlConnection(ConString);
try
{
DBConnnect.Open();
MySqlCommand cmd = DBConnnect.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into tbl_data (Student_Number, Name, Strand, Section) values('"+textBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"', '"+textBox4.Text+"')";
cmd.ExecuteNonQuery();
DBConnnect.Close();
MessageBox.Show("Student registered successfully");
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}