azad education azad education

The next-generation blog, news about technology.

India (HQ)

[email protected]

Loan Management project c# load data from database to data grid view check party statement

azad education
Azad Education Dec 02, 2022 · 10 min read

Loan Management Project c# and SQL server

Hello, friends today I am sharing with you my experience coding with projects. In this software, we can manage all loan management accounts of clients can manage loan credit and debt with interest. this is part 4 of the loan management project.

Feature's of Loan Management Software.

  • Party Statement's
  • Pay EMI
  • Increase Loan Amount
  • Export Party Statement in PDF or Excel
  • More features you want to add to this project can be contacted and commented on by us.

Add loan account Form

Change this save function code.

private void saveData()
        {

            try
            {
                SqlConnection con = new SqlConnection(data.SqlConStr);
                con.Open();
                string queery = "INSERT INTO accounts(Account_Name,number,bank,description,Balance,cr_date,loan_rec_in,interest_rate,duration,processing_fee)" +
                    "VALUES (@name,@number,@bank,@description,@balance,@cr_date,@loan_rec_in,@interest_rate,@duration,@processing_fee) SELECT SCOPE_IDENTITY()";
                SqlCommand cmd = new SqlCommand(queery, con);
                cmd.Parameters.AddWithValue("@name", txtAccountName.Text);
                cmd.Parameters.AddWithValue("@number", txtAccountNumber.Text);
                cmd.Parameters.AddWithValue("@bank", txtLenderBank.Text);
                cmd.Parameters.AddWithValue("@description", txtDescription.Text);
                cmd.Parameters.AddWithValue("@balance", txtOpeningBalance.Text);
                cmd.Parameters.AddWithValue("@cr_date", dtBalance.Text);
                cmd.Parameters.AddWithValue("@loan_rec_in", loanReceivedIn.Text);
                cmd.Parameters.AddWithValue("@interest_rate", txtIntrestRate.Text);
                cmd.Parameters.AddWithValue("@duration", txtDuration.Text);
                cmd.Parameters.AddWithValue("@processing_fee", txtProcessingFees.Text);
                //cmd.ExecuteNonQuery();
                int acc_id = Convert.ToInt32(cmd.ExecuteScalar());
                if (Convert.ToInt32(txtOpeningBalance.Text) > 0 && txtOpeningBalance.Text != "Opening Balance")
                {
                    string emi = "INSERT INTO emis(acc_id,txn_type,payType,amount,interest,date)" +
                    "VALUES (@acc_id,@txn_type,@payType,@amount,@interest,@date)";
                    SqlCommand cmd_emi = new SqlCommand(emi, con);
                    cmd_emi.Parameters.AddWithValue("@acc_id", acc_id);
                    cmd_emi.Parameters.AddWithValue("@txn_type", "Opening Txn");
                    cmd_emi.Parameters.AddWithValue("@payType", loanReceivedIn.Text);
                    cmd_emi.Parameters.AddWithValue("@interest", 0);
                    cmd_emi.Parameters.AddWithValue("@amount", txtOpeningBalance.Text);
                    cmd_emi.Parameters.AddWithValue("@date", dtBalance.Text);
                    cmd_emi.ExecuteNonQuery();
                }
                MessageBox.Show("Account Created Successfully", "Loan Account", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Form1 f1 = new Form1();
                f1.loadData();
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

Form1 Data grid view cell on double click.

if (homedgv.SelectedCells.Count > 0)
            {
                int selectedrowindex = homedgv.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = homedgv.Rows[selectedrowindex];
                string id = Convert.ToString(selectedRow.Cells["id"].Value);
                data.AccountID = id;

            }
            OpenChildForm(new partyStatement());

Party Statement Form Load on form load.

public void loadData()
        {

            string selectSQL = "select * from accounts where id='" + data.AccountID + "'";
            SqlConnection con = new SqlConnection(data.SqlConStr);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataReader reader;

            try
            {

                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    lblAmount.Text = reader["Balance"].ToString();
                    lblPartyName.Text = reader["Account_Name"].ToString();
                }
                con.Close();
                string emi = "select * from emis where acc_id='" + data.AccountID + "'";
                SqlCommand sCommand = new SqlCommand(emi, con);
                SqlDataAdapter sAdapter = new SqlDataAdapter(sCommand);
                SqlCommandBuilder sBuilder = new SqlCommandBuilder(sAdapter);
                DataSet sDs = new DataSet();
                sAdapter.Fill(sDs, "emi");
                DataTable sTable = sDs.Tables["emi"];
                con.Close();
                emiDgv.DataSource = sDs.Tables["emi"];
                emiDgv.ReadOnly = true;
                emiDgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                emiDgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Loan Account");
            }
        }

avatar

Azad Mohammed

An editor at AzadEducation
View Articles

I'am Azad, These blogs, tech skills and programing news, I am sharing with my exprience. I have 4+ year experiece in the web development. Also we are learning investing ideas. I believe in "big mind big dream", that will convert in smart mind. You can follow me on Linkedin profile.

Categories
C#
10
Java Script
8
SEO
4
Quick Hack Solution Tips
4

Subscribe to our mailing list!

We don't spam