Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys,

im for first time using a database in c#.
I would like to know how do i read, compare values
in different data tables.

And most important, how do i get all values of a row from a datatable.
I have 4 DataTables. In ech table are some rows. Now i get that
rows into a form. By doing this, i have created relations to the tables from
the dataset.

After that, i opened the dataset. I have seen that it is possible on "right-click"
to add a method for searching/output values from tables, querry.

Now i started the querry helper, by clicking my table and set the method settings,
for searching my value. Afterwards i opened my form and set the Table and the
table adapter. I searched that table with "foreach". Everything works fine.

But, now i need to search another table, and by doing this by the same proces
as explained it doesnt work, it tells me on creating the query, the
shema is another as the main query.

Let me know if you need a more precise explaination.

Thank you

Greets Niko
Posted
Updated 26-Nov-12 21:07pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Nov-12 2:44am    
I don't need any explanations, but probably you do, if you want any answers... :-)
"It seems that im not doing it correctly" is not informative at all; isn't it obvious? You are the only one who knows your problem, so this is you who needs to judge what is sufficient information. Use some logic...
--SA
niko_tells 27-Nov-12 2:53am    
ok im sorry, gonna update it

1 solution

C#
using System.Data;
using System.Data.SqlClient;

SqlConnection con=new SqlConnection("Connection string of your database");

string query="select * from users";
SqlDataAdapter da=new SqlDataAdapter(query, con);
DataTable dt=new DataaTable();
da.fill(dt);

foreach(DataRow dr in dt.Rows)
{
   if(dr["FirstName"].ToString()== fnameTxtBox.Text)
       Label.Text = "Welcome "+fnameTxtBox.Text;
}   // you can loop through all the records (i.e Rows) using this loop, modify the code as per requirements
 
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