Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day everyone please i am working on c# windowsform applicaton for loan i want to join two database base on a particular column. i have  two database(employement,loanform) please i want to join the two of them to a new table so there will not be duplicate colums)
database employementform(1st database)
 id          employementnumber      fullname      age      
1            ts/02/001               adedoyin     40
2            ts/02/003                chisom      25
3            ts/02/012                 femi       44
4            ts/02/022                 James      33
 
 
database loanform(2nd database)
id          employementnumber      amountofloan         percent         totalamount
1           ts/02/003                10000               10                100000
2           ts/02/003               2500                 10                 2750
3            ts/02/01               1200                 10               1320
 
i want to join them on a new database to show on a datagridview and i want it to be like this:
database join
 id     employementnumber fullname     age    amountofloan   percent  totalamount
 1      ts/02/003          adedoyin     40       10000           10     100000
2        ts/02/003        adedoyin      40        2500            10     2750
3        ts/02/01         chisom       25        1200            10     1320


What I have tried:

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\odt\Documents\Loanapp.mdf;Integrated Security=True;Connect Timeout=30");
          DataTable dt = new DataTable();
          con.Open();
          SqlCommand cmd = con.CreateCommand();
          cmd.CommandType = CommandType.Text;
          cmd.CommandText = "select * from loanform,Registrationform";
          cmd.ExecuteNonQuery();

          SqlDataAdapter da = new SqlDataAdapter(cmd);
Posted
Updated 30-May-19 9:19am
v2

1 solution

What you need is a JOIN: SQL Joins[^]
Something like:
SQL
SELECT a.id, a.Employmentnumber, b.fullname, b.age, a.amountofloan, a.percent, a.totalamount FROM loanform a
JOIN employmentform b ON a.employmentnumber = b.employmentnumber

But ... that's a poor bit of design you have there.
Instead of storing EmploymentNumber in each row of the loanform, store the ID from the employmentform as a foreign key, and instead of storing the age store the DOB - you can work out the age from that, but age changes, DOB doesn't.

And those aren't databases, they are tables within a database - it's very important to use the right terminology, or answers can be very, very wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900