0
I have 1 table with 2 columns (Code and Value). I’m writing a code in C# and I have a variable taxpercentage. What I need is to return the column value Code, when the variable taxpercentage is equal to the value of the column Value. I have to read the column Value and when I find a match, I return the Code.
For example: If my variable is 23.00, I want to return the 6 ! I tried this code, but it doesn’t work:
conn.Open();
SqlCommand command = new SqlCommand("SELECT Value, Code FROM IVA", conn);
SqlDataReader rd = command.ExecuteReader();
if(rd.HasRows)
{
while (rd.Read())
{
if (taxpercentage == rd["Value"].ToString())
{
codeiva = rd["Code"].ToString();
Console.WriteLine(codeiva);
}
}
}
conn.Close();
Does anyone know how I can do ?
How you are assigning value in variable
taxpercentage
?– Ismael
Sets the variable declaration
taxpercentage
– igventurelli
The taxpercentage variable is a value I’m reading from an xml file, so: Xmlnodelist taxlist = doc.Getelementsbytagname("Tax"); foreach (Xmlnode xn1 in taxlist) { string taxpercentage = xn1["Taxpercentage"]. Innertext; }
– D C