this is my code, How can I search inside Table1 and Table2 with same textbox1.text value, by the other words:
// [Table1]
| name | age |
| -------- | -------------- |
| aaa | 12 |
| bbb | 13 |
| ccc | 14 |
// [Table2]
| name | gender |
| -------- | -------------- |
| aaa | male |
| bbb | female |
| ccc | male |
How can I get age and gender values and display it inside txt.Text when [name] equal to textbox1.text?
thanks
con.Open();
// search inside table1
OleDbCommand da = new OleDbCommand("SELECT * FROM [Table1] WHERE Table1.name='@name",con);
//search inside table2
OleDbCommand da2 = new OleDbCommand("SELECT * FROM [Table2] WHERE Table2.name='@name", con);
// give @name value to table1 and table2 as parameters
da.Parameters.AddWithValue("@name",textBox1.Text);
da2.Parameters.AddWithValue("@name", textBox1.Text);
// its time for executing
OleDbDataReader dr = da.ExecuteReader();
OleDbDataReader dr2 = da2.ExecuteReader();
// now display it in textBox as a string
if (dr.Read())
{
dr2.Read();
for (int x = 0; x < 4;x++ ) {
if(dr[x].ToString() !=""){
txt.Text += dr[x].ToString() + System.Environment.NewLine;
}
}
}
else { MessageBox.Show("error"); }
con.Close();