I'm new here and also in the world of programming, today I managed for the first time to make the connection from C # to SQL, when making a simple connection with BD I can insert records, but when trying to insert 2 data in the same table simultaneously he creates 2 registers or inserts only the last, please help me, follow the code below ...
private void bt_Cadastrar_Click(object sender, EventArgs e)
{
if (bt_Cadastrar.Text == "Salvar")
{
tb_ID.Enabled = false;
bt_Cadastrar.Text = "Cadastrar";
}
Int16 Cheque, Convenio;
if (cb_Cheque.Checked) Cheque = 1;
else Cheque = 0;
if (cb_Convenio.Checked) Convenio = 1;
else Convenio = 0;
SqlConnection conn = new SqlConnection("Server= localhost; Database=Cadastros; Integrated Security=true"); //Cria a conexão com o Banco de dados devido a Dll que tem na pasta do programa.
SqlCommand cmd = new SqlCommand("insert into ccliente (Nome) values ('" + tb_Nome.Text.ToUpper() + "')", conn); //Comando SQL para criar inserir um item em uma tabela existente
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
/*
cmd = new SqlCommand("insert into ccliente (CPF) values ('" + tb_CPF.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (RG) values ('" + tb_RG.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (CEP) values ('" + tb_CEP.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Cidade) values ('" + tb_Cidade.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Email) values ('" + tb_Email.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Telefone1) values ('" + tb_Telefone1.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Telefone2) values ('" + tb_Telefone2.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Observacao) values ('" + tb_Observacao.Text.ToUpper() + "')", conn);
cmd = new SqlCommand("insert into ccliente (Cheque) values ('" + Cheque + "')", conn);
cmd = new SqlCommand("insert into ccliente (Convenio) values ('" + Convenio + "')", conn);
*/
}
If necessary, the link to the complete project is below: goo.gl/6P8Hwc (Please, if any moderator thinks this is wrong you can delete the link, I'm new here and I do not know the rules yet). >