Making a console app, where I need to edit some user credentials. But sometimes I need to edit just one thing, and I want to be able to just press ENTER, when it comes to the other stuff that doesn't need updating.
So it gets the Id to edit from the int editId, and perhaps I want to just edit the address. So I want to be able to just press ENTER on the rest of the records, and not update them.
So it gets the Id to edit from the int editId, and perhaps I want to just edit the address. So I want to be able to just press ENTER on the rest of the records, and not update them.
PHP Code
<?php
private void EditAccount()
{
Console.WriteLine("\nEnter account number to edit:");
int editId = int.Parse(Console.ReadLine());
Console.WriteLine("Edit account holder:");
string editHolder = Console.ReadLine();
Console.WriteLine("Edit address of account holder:");
string editAddress = Console.ReadLine();
Console.WriteLine("Edit zipcode of account holder:");
string editZip = Console.ReadLine();
Console.WriteLine("Edit country of account holder:");
string editCountry = Console.ReadLine();
Console.WriteLine("Edit phone of account holder:");
int editPhone = int.Parse(Console.ReadLine());
Console.WriteLine("Edit account balance:");
int editBalance = int.Parse(Console.ReadLine());
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myCon"].ConnectionString);
{
con.Open();
string updateQuery = "UPDATE BankSystem SET accHolder = '" + editHolder +
"', accAddress = '" + editAddress +
"', accZip = '" + editZip +
"', accCountry = '" + editCountry +
"', accPhone = '" + editPhone +
"', accBalance = '" + editBalance +
"' WHERE accId = " + editId;
using (SqlCommand cmd = new SqlCommand(updateQuery, con))
{
cmd.Parameters.AddWithValue("accHolder", editHolder);
cmd.Parameters.AddWithValue("accAddress", editAddress);
cmd.Parameters.AddWithValue("accZip", editZip);
cmd.Parameters.AddWithValue("accCountry", editCountry);
cmd.Parameters.AddWithValue("accPhone", editPhone);
cmd.Parameters.AddWithValue("accBalance", editBalance);
int rows = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine("Account was updated.");
}
}
}
catch (SqlException ex)
{
Console.WriteLine("Something went wrong.", ex.ToString());
}
public void editAccount()
{
EditAccount();
}
}


