Click here to Skip to main content
16,004,458 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,
I want to get data from tow table from MS access database. Database name Record and table name Area (SNO, AreaCode, Code ) City (SNO, Name , city code ) I want to make a single search single search query on base of SNO

Kindly tell me i have code which get data from one table and search in one table i want to make for two table

What I have tried:

C#
OleDbConnection mycnc = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0; Data Source=F:\\Database1.accdb");
OleDbDataAdapter myadpt = new OleDbDataAdapter();
DataSet mydtSet = new DataSet();
myadpt.SelectCommand = new OleDbCommand();

myadpt.SelectCommand.CommandText = "select * from area where SNO=" + textBox1.Text + "";

myadpt.SelectCommand.Connection = mycnc;
mycnc.Open();
myadpt2.Fill(mydtSet, "area");
mycnc.Close();

dataGridView1.DataSource = mydtSet;
dataGridView1.DataMember = "area";
MessageBox.Show("successfully search !");
textBox1.Clear();
Posted
Updated 1-Jun-16 20:21pm
v4

1 solution

i think you can use SQL syntax using union all

myadpt.SelectCommand.CommandText = "select * from area where SNO=" + textBox1.Text + " UNION ALL SELECT * FROM CITY WHERE SNO=" + textbox1.Text + ""; 
 
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