INSERT with information from a database inside another C #

0

I'm trying to make an application where I can back up multiple banks at the same time by putting bank information (which will be backed up) within a bank that will allocate this information.

But I can not put the information through a syntax error, could you help me by saying what's wrong with the syntax?

        private void cadastroButton_Click(object sender, EventArgs e)
    {
        try
        {
            if (dataBaseBox.CheckedItems.Count == 0)
            {
                MessageBox.Show("Por favor selecione um Banco de Dados.");
                return;
            }

            else
            {
                foreach (var check in dataBaseBox.CheckedItems)
                {
                    cn = new SqlConnection(connString2());
                    cn.Open();
                    string query;
                    query = "INSERT INTO bancos(nome,diretorio,hora) VALUES = '" + check.ToString() + "','"+horarioBox+"' + '"+locationTextBox.Text + "'";
                    cmd = new SqlCommand(query,cn);
                    cmd.ExecuteNonQuery();
                    cn.Close();

                }

            }
            MessageBox.Show("Backup executado com sucesso!");

        }

    
asked by anonymous 09.06.2017 / 21:24

1 answer

0

The correct one is:

"INSERT INTO bancos(nome,diretorio,hora) VALUES ('" + check.ToString() + "','"+horarioBox+"' + '"+locationTextBox.Text + "');";

and not

VALUES = 'TESTE','TESTE','TESTE'

ps. Instead of using parameters in the commands, see: link

    
09.06.2017 / 21:33