INSERT with database information inside another C#database

Asked

Viewed 316 times

0

I am trying to make an application where I can back up several banks at the same time by placing the information of the banks (which will be backed up) inside a bank that will allocate this information.

But I can not put the information for a syntax error, could help me telling what is wrong in 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!");

        }

inserir a descrição da imagem aqui

  • In fact the same mistake is that this is insecure, one of the reasons to give the error. Of course doing right may cause error, but at least it helps to avoid. Search right here about this, see: https://answall.com/a/183986/101

1 answer

0


  • That’s right! @Rovann, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.