public List <Account_IBAN> SelectAccount(string code) { Account_IBAN ac = new Account_IBAN(); List <Account_IBAN> acList = new List <Account_IBAN>(); using (SqlConnection connection = new SqlConnection(constring)) { if (connection != null && connection.State == ConnectionState.Closed) { connection.Open(); } SqlCommand cmd = new SqlCommand("SP_SelectAccount", connection); // 2. set the command object so it knows to execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; SqlParameter paramName = new SqlParameter(); paramName.ParameterName = "@code"; paramName.Value = code; cmd.Parameters.Add(paramName); SqlDataAdapter adapt = new SqlDataAdapter(cmd); DataSet AccDS = new DataSet(); adapt.Fill(AccDS, "Account"); connection.Close(); if (AccDS.Tables["Account"].Rows.Count > 0) { foreach (DataRow row in AccDS.Tables["Account"].Rows) { ac = new Account_IBAN(); ac.Code = row["Code"].ToString(); ac.account_id = Convert.ToInt32(row["Account_ID"].ToString()); ac.firstname = row["Account_name"].ToString(); ac.surname = row["Account_Surname"].ToString(); ac.phone = row["Account_Phone"].ToString(); ac.ssn = row["Account_SSN"].ToString(); ac.amount = Convert.ToDecimal(row["Amount"]); ac.Username = row["Username"].ToString(); ac.PIN = row["PIN"].ToString(); acList.Add(ac); } } } return(acList); }
public void SetAccount() { Account_IBAN a = new Account_IBAN(); List <Account_IBAN> ab = new List <Account_IBAN>(); ConnectionDB connectionDB = new ConnectionDB(); string Code = cb_Up_Code.SelectedItem.ToString(); ab = connectionDB.SelectAccount(Code); a = ab.FirstOrDefault(); num_Up_Amount.Value = a.amount; txt_Up_Firstname.Text = a.firstname; txt_Up_Surname.Text = a.surname; txt_Up_Phone.Text = a.phone; txt_Up_SSN.Text = a.ssn; txt_Up_Username.Text = a.Username; txt_Up_PIN.Text = a.PIN; lbl_Up_AccID.Text = a.account_id.ToString(); }