Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:37:53+00:00 2026-05-31T02:37:53+00:00

My question is how to assign the data of the table to any variable..

  • 0

My question is how to assign the data of the table to any variable..
I asked to retrieve forgotten password of employee through his email address inputed in textbox and send it to his mail account..
I already fetched the data but don’t know how to assign that password in email body

my code is here

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace TelerikLogin.Models.ViewModels
{
    public class ForgotPassword
    {
        public int user_id { get; set; }
        public string user_login_name { get; set; }
        public string user_password { get; set; }

        [Required]
        [Display(Name="Email Address : ")]
        public string user_email_address { get; set; }
    }
}

View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TelerikLogin.Models.ViewModels.ForgotPassword>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ForgotPassword
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>ForgotPassword</h2>
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>

<% using (Html.BeginForm("ForgotPassword", "Account", FormMethod.Post))
   { %>

   <%: Html.LabelFor(m => m.user_email_address) %>
   <%: Html.TextBox("user_email_address")%>
      <%: Html.ValidationSummary(true) %>

<input type="submit" value="Submit"/>

Controller

public ActionResult ForgotPassword()
{
    return View();
}

[HttpPost]
public ActionResult ForgotPassword(string user_email_address)
{


    SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\MVC3\TelerikLogin\TelerikLogin\App_Data\Login.mdf;Integrated Security=True;User Instance=True");

    DataTable dt1 = new DataTable();

    string strQuery = string.Format("SELECT user_password FROM [user_master] WHERE user_email_address='{0}'",user_email_address);



    conn.Open();

    SqlDataAdapter da1 = new SqlDataAdapter(strQuery, conn);
    da1.Fill(dt1);

    LoginEntities3 le= new LoginEntities3();

   conn.Close();

//...... Below is the query where i fetch the password in var pwd

    var pwd = from u in  new LoginEntities3().user_master
               where u.user_email_address == user_email_address select u.user_password;




    if (dt1.Rows.Count > 0)
    {


        MailAddress mailfrom = new MailAddress("myid@gmail.com");
        MailAddress mailto = new MailAddress(user_email_address);
        MailMessage newmsg = new MailMessage(mailfrom, mailto);

        newmsg.Subject = "Your Password";

**// Here i assign pwd to messege body then it gives  an error of type casting so i converted it in To string**

        newmsg.Body = pwd.ToString();



        SmtpClient smtps = new SmtpClient("smtp.gmail.com", 587);
        smtps.UseDefaultCredentials = false;
        smtps.Credentials = new NetworkCredential("myid@gmail.com", "password");
        smtps.EnableSsl = true;
        smtps.Send(newmsg);


        return RedirectToAction("About", "Home");
    }


   return View();
}

In newmsg.body
i assign the variable pwd(which fetched the password of user) then it gives me an error of type casting so i use To String() method
so it mails the sql query not password in the msg body..
So how to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:37:54+00:00Added an answer on May 31, 2026 at 2:37 am

    Try This

    string pwd = (from u in new LoginEntities3().user_master
    where u.user_email_address == user_email_address select u.user_password).ToString();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have data in table X: id assign team ---------------------- 1 hunkim A
How to assign a variable to returned JSON data that has been manipulated with
My question is if we can assign/bind some value to a certain item and
There is a similar question How can I assign the result of a subroutine
a short question: is it possible to assign the result of a calculation within
This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more
When I launch the app in question I load up a table from an
My question is how to assign the DataType value for columns of special SQL
Objective c | xcode | iphone question Im building a model(data) class for a
I have a table of data in MS Access 2007. There are 6 fields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.