Problem getting data from 2 tables match.
I have 2 tables where "userid" is common. first table has Username along with userid. And the second table has loan details along with userid. Now i want to make a search form where the client can enter Username to search for Loan details. How do i do it? It is kinda urgent.

Kirtan PatelRank #292 · 8.6K reputationPosted Oct 19, 2009, 9:22 AM EDT
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows.Count > 0)
{
//show CurrentSelected Row's Column 1 value in TextBox1
textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
//show CurrentSelected Row's Column 2 value in TextBox2
textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
}
}
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 7:47 AM EDT
dont forget to mark "Do you like this answer" if my answer helped you :)
private void btnSearch_Click(object sender, EventArgs e) { //Connecting to database SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"); //Join query SqlCommand comm = new SqlCommand("SELECT Table1.userid, Table1.username, Table2.loandetail FROM Table1 INNER JOIN Table2 ON Table1.userid = Table2.userid where Table1.username=@username",con); comm.Parameters.AddWithValue("@username", txtSearch.Text.Trim()); DataTable dt = new DataTable(); SqlDataAdapter da= new SqlDataAdapter(comm); da.Fill(dt); //Show Data In DataGridView dataGridView1.DataSource = dt; con.Close(); }SELECT Table1.userid, Table1.username, Table2.loandetail FROM Table1 INNER JOIN Table2 ON Table1.userid = Table2.userid where Table1.username=
utsav rathour52 reputationPosted Oct 18, 2009, 8:38 AM EDT
utsav rathour52 reputationPosted Oct 18, 2009, 7:10 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 18, 2009, 7:46 PM EDT
utsav rathour52 reputationPosted Oct 19, 2009, 4:34 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 19, 2009, 4:37 AM EDT
can you send me your code in Zip File
just upload it here and Send Me Download link
i will Resolve it Quickly ( [email protected] )
utsav rathour52 reputationPosted Oct 19, 2009, 5:02 AM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 19, 2009, 5:42 AM EDT
congrats problem solved :)
dont forget to mark "Do you like this answer" please :)
It was Happening Because Your Database Design Was not Correct ..
1. You have Defined AutoNumber type in DebtorID and in Loan Table you have Defined debtor_id as Text DataType ( cause od Error Type missmatch)
2. you have not defined foreign key relation ship between debtors and Loan table
corrected Database is in "Application1" folder
Download Corrected Code
utsav rathour52 reputationPosted Oct 19, 2009, 6:43 AM EDT
utsav rathour52 reputationPosted Oct 19, 2009, 8:48 AM EDT
this.textBox1.Text = ds.Tables["loan"].Rows[this.dataGridView1.CurrentCell.RowIndex][3].ToString();
Now with datatable how do i show this. Sry to bother again.
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 19, 2009, 8:55 AM EDT
to do this we need to fill ds.Table["load"] with query "Select * from loan"
separately because in previous code we have filled the dt with mixed data from both tables "loan" and "debtors"
and if you need more help just let me know i will send you that files with modified code :)
just let me know where you want to update and how you want to update it :)
thank you :)
utsav rathour52 reputationPosted Oct 19, 2009, 9:07 AM EDT
enerally I want to be able to show the data selected from the datagridview( after search) in a text box. for example the amount, or any other data. Could you help me do that and provide me the code. i would love to do it by myself with some help but currently i am runnin out of time.
Thanks
utsav rathour52 reputationPosted Oct 19, 2009, 9:28 AM EDT