Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# database
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 26-Nov-12 20:23pm
Edited 26-Nov-12 21:07pm
Sergey Alexandrovich Kryukov at 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...
niko_tells at 27-Nov-12 2:53am
ok im sorry, gonna update it

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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();
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


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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 598
1 OriginalGriff 280
2 George Jonsson 258
3 CPallini 190
4 Animesh Datta 130
0 OriginalGriff 5,985
1 Sergey Alexandrovich Kryukov 5,341
2 CPallini 4,760
3 George Jonsson 3,400
4 Gihan Liyanage 2,522

Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100