How can I use / retrieve two values from a SELECT query? I have done it before but cannot remember how to do it...!!!
EXAMPLE:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserConnectionString"].ConnectionString);
con.Open();
string cmdStr2 = "SELECT Password FROM UserTable WHERE EmailAddress= '" + UserEmail + "'";
SqlCommand checkPword = new SqlCommand(cmdStr2, con);
string password = checkPword.ExecuteScalar().ToString();
con.Close();
Here im just getting the password, but what about if I was doing SELECT Username, Password FROM UserTable........ How woud I get and use those two values into two separate variables..?
Shifty001
Member
78 Points
182 Posts
How to use to values returned in a SELECT query ???
Apr 18, 2012 08:13 PM|LINK
Hi all, simples one for you...
How can I use / retrieve two values from a SELECT query? I have done it before but cannot remember how to do it...!!!
EXAMPLE:
Here im just getting the password, but what about if I was doing SELECT Username, Password FROM UserTable........ How woud I get and use those two values into two separate variables..?
Thanks!
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: How to use to values returned in a SELECT query ???
Apr 18, 2012 08:17 PM|LINK
return the values into a DataSet and then you can consume the rows.
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
bugwee
Member
354 Points
72 Posts
Re: How to use to values returned in a SELECT query ???
Apr 19, 2012 12:53 AM|LINK
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserConnectionString"].ConnectionString)) { SqlCommand Comm1 = new SqlCommand("SELECT Password,username FROM UserTable WHERE EmailAddress= '" + UserEmail + "'", con); con.Open(); SqlDataReader DR1 = Comm1.ExecuteReader(); if (DR1.Read()) { string password = DR1.GetValue(0).ToString(); string username = DR1.GetValue(1).ToString(); } con.Close(); }Shifty001
Member
78 Points
182 Posts
Re: How to use to values returned in a SELECT query ???
Apr 19, 2012 05:00 PM|LINK
Thank you....