public void AccessTableAdd() { String Criteria; Criteria = "PartnerID =" + textBox1.Text; Rs.MoveFirst(); //go to the beginning to start serach Rs.Find(Criteria); //Either We find the record(s), which is the first record if there are more than one //If record is found the file pointer stays at it //if not found, the file pointer has passed eof meaning eof = true if (Rs.EOF == true) { //not found Rs.AddNew(); SaveinTable(); Rs.Update(); MessageBox.Show("Record Added succesfully"); ClearBoxes(); return; } else { //found MessageBox.Show("Duplicate Record, try another PartnerID"); return; } }
//Adding new record into DB private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox8.Text == "" || textBox9.Text == "" || textBox10.Text == "" || textBox11.Text == "" || textBox12.Text == "" || textBox13.Text == "" || textBox14.Text == "" || textBox15.Text == "" || textBox16.Text == "" || textBox17.Text == "" || textBox18.Text == "") { MessageBox.Show("Please Fill up all boxes"); return; } String Criteria; Criteria = "ContactID =" + textBox1.Text; Rs.MoveFirst(); //go to the beginning to start serach Rs.Find(Criteria); //Either We find the record(s), which is the first record if there are more than one //If record is found the file pointer stays at it //if not found, the file pointer has passed eof meaning eof = true if (Rs.EOF == true) { //not found Rs.AddNew(); SaveinTable(); Rs.Update(); MessageBox.Show("Record Added succesfully"); ClearBoxes(); return; } else { //found MessageBox.Show("Duplicate Record, try another ISBN"); return; } }
private void coletadados() { ADODB.Recordset dados = new ADODB.Recordset(); ADODB.Recordset itens = new ADODB.Recordset(); String SQL = "SELECT * FROM SAÍDA WHERE (COD_SAI = " + _id + ");"; String SQLProdutos = "SELECT COD, ESTOQUE FORM PRODUTOS;"; //Buscando os itens dados.Open(SQL, new Conexao().getDb4(), ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic); itens.Open(SQLProdutos, new Conexao().getDb4(), ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic); while (!(dados.EOF || dados.BOF)) { itens.Find("cod =" + dados.Fields["[cod do CD]"].Value, 0, ADODB.SearchDirectionEnum.adSearchForward); if (!(itens.BOF || itens.EOF)) { itens.Fields["Estoque"].Value = Convert.ToInt64(itens.Fields["Estoque"].Value) + Convert.ToInt64(dados.Fields["Qunatidade"].Value); } dados.MoveNext(); } //EXcluindo ITENS SQL = "DELETE FROM SAÍDA WHERE (COD_SAI = " + _id + ");"; dados.Close(); dados.Open(SQL, new Conexao().getDb4(), ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic); //Excluindo capa SQL = "DELETE FROM cod_sai WHERE(COD_SAI = " + _id + ");"; dados.Close(); dados.Open(SQL, new Conexao().getDb4(), ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic); }