This is with reference to my previous question:
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();
Have a look at Retrieving Data Using a DataReader (ADO.NET)
and more specifically at the line
at any of the get functions
for eg
SqlDataReader.GetString Method and SqlDataReader.GetInt32 Method
so you could try something like