TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Daniel Koh
NA
60
15.5k
Retrieving a single value from database
Oct 18 2017 2:50 AM
Hi, how do you retrieve a single value stored in a datatable via user input to choose column? for example my datatable has 2 columns, one for username and password. I would like to be able to enter my username in a program to retrieve the password from the database that is in the same row as the username. How do I do that? This part of my program is similar to that of those "forget password" things where you have to answer a security question and enter your username to retrieve your lost password. Much help appreciated thanks.
This is the code for checking if the security questions have been answered correctly:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Daniel Koh\Documents\AccountData.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) From [Table] where Username='" + textBox1.Text + "' and EmployeeId ='" + textBox2.Text + "' and SecurityQuestionAnswer='" + textBox3.Text + "' and SecurityQuestionType='" + comboBox1.SelectedItem.ToString() + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if ((dt.Rows[0][0].ToString() == "1"))
{
[MISSING CODE HERE]
MessageBox.Show(password);
}
else
{
MessageBox.Show("Please check your Username, Security Question Answer and EmployeeID");
}
}
Reply
Answers (
3
)
Cannot configure WampServer
What kind of data can be extracted from data mining?