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

  • Home
  • SEARCH
  • 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 8963425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:21:08+00:00 2026-06-15T16:21:08+00:00

This is with reference to my previous question: Search data in database I have

  • 0

This is with reference to my previous question:

Search data in database

I have used the following code to execute my query. But I’m having issues for storing the value from the command and then use that result to compare the value.

This is my code:

SqlDataReader sdrDatanew = null;
string strnew;
string connectionString = WebConfigurationManager.ConnectionStrings["Gen_LicConnectionString"].ConnectionString;
SqlConnection connew = new SqlConnection(connectionString);
connew.Open();
strnew = "select User_Type from User_Details where User_Type='" + ddlUserSel.SelectedItem.Value + "' AND LoginID = '" + txtUserName.Text + "' AND Password = '" + txtPassword.Text + "'";
SqlCommand sqlCommnew = new SqlCommand(strnew, connew);
sdrDatanew = sqlCommnew.ExecuteReader();
if (sdrDatanew.HasRows)
  {
     if (sdrDatanew.Read())
      {
          //Here I want to store the result from the sqlcommand in a variable
      }
  }

    switch (//Here I want to use the variable in a switch case) //<---
    {
        case 0:
            Response.Redirect("Lic_Gen.aspx");
            break;
        case 1:
            Response.Redirect("Cust_Page.aspx");
            break;
    }

    connew.Close();
  • 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-15T16:21:09+00:00Added an answer on June 15, 2026 at 4:21 pm

    Have a look at Retrieving Data Using a DataReader (ADO.NET)

    and more specifically at the line

    Console.WriteLine("{0}\t{1}", reader.GetInt32(0),reader.GetString(1));
    

    at any of the get functions

    for eg

    SqlDataReader.GetString Method and SqlDataReader.GetInt32 Method

    so you could try something like

    int userType = 0;
    if (sdrDatanew.HasRows)
    {
        if (sdrDatanew.Read())
        {
            userType = sdrDatanew.GetInt32(0); //something like this
        }
    }
    
    switch (userType) //something like this
    {
        case 0:
            Response.Redirect("Lic_Gen.aspx");
            break;
        case 1:
            Response.Redirect("Cust_Page.aspx");
            break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to my previous question but it is a different problem. I
This is an elaboration of a previous question, but as I delve deeper into
This is a continuation question from a previous question I have asked I now
Please use my previous question as reference. I have marked an answer already. Question
Following the help in this question , I am using a reference to my
This is similar to my previous question, but that solution did not solve this
This is a follow-up to this previous question: Complicated COUNT query in MySQL .
I had the following error at previous question: Fluent NHibernate? Am I doing this
In reference to this previous question: Connect through HTTPS instead of HTTP Would this
I have a large non static JAVA function, which uses this reference at several

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.