S
S
spone3792017-03-29 17:15:08
ASP.NET
spone379, 2017-03-29 17:15:08

How to retrieve values ​​from database?

There is a form on which two textboxes (login, password) after an existing user is entered into the database, an edit form should open ... that is, all fields from the database of this user are displayed on another form (the registration form of this user where there are 3 textboxes, dropDownList , checkBoxList, radioButtonList), and I can already change them and re-enter them in the database.
I figured out the user verification form here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class LoginEdit : System.Web.UI.Page
{
    Int32 temp = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["registrationConnectionString"].ConnectionString);
        conn.Open();
        string checkuser = "select count(*) from [reg] where Name = '" + TextBox1.Text + "'";
        SqlCommand com = new SqlCommand(checkuser, conn);
        temp = Convert.ToInt32(com.ExecuteScalar());
        conn.Close();
        if (temp > 0)
        {
            conn.Open();
            string checkPasswordQuery = "select password from [reg] where Name = '" + TextBox1.Text + "'";
            SqlCommand passCom = new SqlCommand(checkPasswordQuery, conn);
            string password = passCom.ExecuteScalar().ToString().Replace(" ", "");

            string checkNameQuery = "select name from [reg] where Name = '" + TextBox1.Text + "'";
            SqlCommand nameCom = new SqlCommand(checkNameQuery, conn);
            string name = nameCom.ExecuteScalar().ToString().Replace(" ", "");
            if (TextBox1.Text == "Admin" & password == TextBox2.Text)
            {
                Session["New"] = TextBox1.Text;
                Response.Redirect("AdminForm.aspx");
            }

            else if (password == TextBox2.Text)
            {
                Session["New"] = TextBox1.Text;
                Response.Write("Password is correct");
                Response.Redirect("RegistrationEdit.aspx");
            }
            
            else
            {
                Response.Write("<script>alert('Password is not correct!')</script>");
            }
        }
        else {
            Response.Write("<script>alert('Username is not correct!')</script>");
        }
    }
    }

, but I don’t know how to display the already completed form of this user, and therefore I am asking for help. Maybe someone has the code, or it's not difficult to write a few lines. Thanks in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question