public void InsertDeposit(decimal newBalance, decimal DepositAmount, string acNo) { try { myDBconnection myDBCon = new myDBconnection(); SqlConnection sqlConnection = new SqlConnection(myDBCon.conStr); string query = "SELECT * FROM NewAtmTable WHERE AccountNumber = @AccountNumber"; SqlCommand myCommand = new SqlCommand(query, sqlConnection); myCommand.CommandText = ("UPDATE NewAtmTable SET Balance=@Balance,Deposit=@Deposit WHERE AccountNumber = @AccountNumber"); sqlConnection.Open(); myCommand.Parameters.AddWithValue("@AccountNumber", acNo); myCommand.Parameters.AddWithValue("@Balance", newBalance); myCommand.Parameters.AddWithValue("@Deposit", DepositAmount); myCommand.ExecuteNonQuery(); new Form6().Show(); this.Hide(); } catch (Exception ex) { throw ex; } }
private void button1_Click(object sender, EventArgs e) { try { var acName = txtAccName.Text; myDBconnection AccNum = new myDBconnection(); var acNo = AccNum.AccountNumber(); var acPin = txtPin; //string query = "INSERT INTO NewAtmTable (AccountNumber,AccountName,Pin)"; //query += "VALUES(@AccountNumber,@AccountName,@Pin)"; string query = "INSERT INTO NewAtmTable (AccountNumber,AccountName,Pin,Balance) VALUES (@AccountNumber,@AccountName,@Pin,@Balance)"; myDBconnection myDBCon = new myDBconnection(); SqlConnection sqlConnection = new SqlConnection(myDBCon.conStr); SqlCommand myCommand = new SqlCommand(query, sqlConnection); myCommand.Parameters.AddWithValue("@AccountNumber", acNo); myCommand.Parameters.AddWithValue("@AccountName", txtAccName.Text); myCommand.Parameters.AddWithValue("@pin", txtPin.Text); myCommand.Parameters.AddWithValue("@Balance", 10000); sqlConnection.Open(); myCommand.ExecuteNonQuery(); if (string.IsNullOrEmpty(txtAccName.Text) || string.IsNullOrEmpty(txtPin.Text)) { MessageBox.Show("Please Fill in The Spaces"); } else { MessageBox.Show("You have successfully Created an account"); new Form2().Show(); this.Hide(); } } catch (Exception ex) { throw ex; } }