Recognize uppercase or lowercase in C #

2

I have a TextBox in which letters are scanned and do a search in Access , the problem I have is that when the keyboard is uppercase it scans the letters in lowercase and vice versa, and at the time of doing the search gives an error in the format of the variable and is because they are in lowercase.

How can I make it identify when they are uppercase or lowercase? this is what I have.

public string selcopert()
    {
        int decValue = 0;
        string query="";
        if (opertname.StartsWith("~") && opertname.EndsWith("~") && opertname.Length > 1)
        {
            string oprt = Regex.Replace(opertname, @"^~UMIH\|(.*)~$", "$1");
            decValue = int.Parse(oprt, System.Globalization.NumberStyles.HexNumber);
            query = "SELECT * where op = '" + decValue + "' ";
        }
        else
        {
            query = "Select * op where = '" + opertname + "' ";
        }
        string op="";
        SqlConnection cone = new SqlConnection(cc.consql);
        cone.Open();
        SqlCommand coms = new SqlCommand(query, cone);
        using (SqlDataReader read1 = coms.ExecuteReader())
        {
            if (read1.Read())
            {
                op = read1[0].ToString();
            }
        }
        cone.Close();
        return op;
    }

Or also that the Regex.Replace recognizes case, but I do not know how to do it.

    
asked by use2105 27.12.2016 в 15:22
source

1 answer

1

If you have problems with the Caps Lock, click on these buttons at the same time:

  

CAPS LOCK + CTRL + SHIFT

     

Source

Regarding your code, follow the recommendations that you have given in the comments:

  • Put ToUpperInvariant () to your variables.
  • Example:

    // Con este método vuelves todos los caracteres a mayúscula.
    string opertname = TextBox1.Text.ToUpperInvariant();
    
        
    answered by 20.03.2017 в 11:18