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 8713365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:19:37+00:00 2026-06-13T05:19:37+00:00

I have a table called students, I want to delete an students info, but

  • 0

I have a table called students, I want to delete an students info, but first I need him/her to re-enter his/her login details before he/she is deleted from the table (Sort of like deactivating your account)

protected void btnLDelete_Click(object sender, EventArgs e)
{
    {
        string strcon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VC_temps.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
        SqlConnection con = new SqlConnection(strcon);

        SqlCommand com = new SqlCommand("CheckUser", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter p1 = new SqlParameter("StudCode", TextBox1.Text);
        SqlParameter p2 = new SqlParameter("Pword", TextBox2.Text);
        com.Parameters.Add(p1);
        com.Parameters.Add(p2);
        con.Open();
        SqlDataReader rd = com.ExecuteReader();
        if (rd.HasRows)
        {

            string command = @"DELETE FROM Student WHERE StudCode= StudCode";
            SqlCommand com2 = new SqlCommand(command, con);
            SqlParameter q1 = new SqlParameter("StudCode", Session["StudCode"]);
            com.Parameters.Add(q1);
            Response.Redirect("Default.aspx");
        }

        else
        {
            Labelinfo.Text = "Invalid username or password.";

        }
    }
}

I also tried using a SP but came with the same results, I don’t get an error but as soon as I click delete I get redirected to my login page and seems that I can Still log in

can someone please help?

  • 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-06-13T05:19:38+00:00Added an answer on June 13, 2026 at 5:19 am

    Inside your if statement, you are not executing the DELETE, only setting up a new command, com2.

    You then add the parameter to the old com command object.

    You need to decide if you want to use the old command, or continue with the new com2, and add the parameter to the proper command. You must then execute the command.

    I am also pretty sure your variable StudCode needs an @ in front. The if would look something like then when you are finished

    rd.Close();
    
    string command = @"DELETE FROM Student WHERE StudCode = @StudCode";
    SqlCommand com2 = new SqlCommand(command, con);
    SqlParameter q1 = new SqlParameter("@StudCode", Session["StudCode"]);
    com2.Parameters.Add(q1); // Also com2 now
    com2.ExecuteNonQuery(); // Added to run the query
    Response.Redirect("Default.aspx");
    

    Depending on what data CheckUser returns, it may be a better idea to call ExecuteScalar initially to look for a specific value instead of whether the CheckUser stored procedure gives you a row back.

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

Sidebar

Related Questions

Hope my subject line was descriptive enough. Basically, I have a table called Students,
i have table called type which contains data family,individual i want in some pages
Say I have a table called students, containing a list of all the students.
I have in DB table Called Students We make some thing like lottery to
I have a table called Students and a table called Majors, Students and Majors
I have table called users and I want to make an exact copy as
I have a table called student which I want to populate from the server.
I have a SQL table called StudentMarks.which consist of StudentID,SubjectName,SubjectMark I want to write
I have a simple ActiveRecord model called Student with 100 records in the table.
I have table called stats . In am inserting yes or no in the

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.