Click here to Skip to main content
11,920,156 members (57,609 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# MySQL
This is probably a silly and very easy question but how do you use a result from a query in a if statement. I am querying a table and if the result has a certain value I want it to carry out a function.
Code so far:
private void ButtonLogin_Click(object sender, RoutedEventArgs e)
    string connectionSQL = @"server=xxxxxxxxxxx;user id=xxxxxxxxxxxx;password=xxxxxxxx;database=xxxxxxxx";
    MySqlConnection cs = new MySqlConnection(connectionSQL);
    DataSet ds = new DataSet();
    MySqlDataAdapter da = new MySqlDataAdapter("Select username, password, type from Admin", cs);
    MySqlCommandBuilder cmd = new MySqlCommandBuilder(da);

I want to do a if statement on values in ds in column type.
Posted 3-Apr-13 16:31pm
Edited 3-Apr-13 20:08pm
ThePhantomUpvoter 3-Apr-13 22:31pm
You get your result, iterate through the result, check for your condition in the if statement, if the condition is met call your function.
Tadit Dash 3-Apr-13 23:33pm
Have you tried anything ?
Please post the code and indicate where exactly you want to this ?
Member 9611735 4-Apr-13 0:54am
question updated
patel_vijay 3-Apr-13 23:50pm
Are you using traditional ADO.Net or entity framework ?
Shine Ashraf 4-Apr-13 1:22am
Have you tried ds.tables[]["columnType"] ?

1 solution

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

Solution 1

Now you can use your DataSet ds.

if you use indexes like table 0 and row 0:
string user = ds.Tables[0].Rows[0];
string pass = ds.Tables[0].Rows[1];

or you can use names of the tables and rows:
string user = ds.Tables["MyTableName"].Rows["Username"];
string pass = ds.Tables["MyTableName"].Rows["Password"];

Good luck,

* Note that you missed closing the connection, [cs.Close();]

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

  Print Answers RSS
0 OriginalGriff 455
1 phil.o 170
2 CPallini 150
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,153
3 George Jonsson 2,810
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2015
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