Click here to Skip to main content
Rate this: bad
good
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
v2
Comments
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...
--SA
niko_tells at 27-Nov-12 2:53am
   
ok im sorry, gonna update it

1 solution

Rate this: bad
good
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();
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

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 310
1 Sergey Alexandrovich Kryukov 166
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,077
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web03 | 2.8.140814.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