Click here to Skip to main content
13,045,285 members (79,967 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 15:31pm
Updated 3-Apr-13 19: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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2017
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