C# windows form

Hi Guys,

I have built some windows form app that checking items in the database if they are exist.

The issue is when  I type in lower case at the textbox it doesn't find the item, but if I type in capital word it works fine and find my item in the database.

how can I program it to find in any case:
Here is my code:
 private void button1_Click(object sender, EventArgs e)
        {
            RMSmasterDBEntities Rmsdb = new RMSmasterDBEntities();
            ALThompsonCRMEntities crmdb = new ALThompsonCRMEntities();

            string poNumber = txtpo.Text;
            t_PO_Register Por = new t_PO_Register();
          

            //check po in erp system
            var chkerp = crmdb.t_PO_Register.Where(p => p.PONumber == poNumber).FirstOrDefault();

            if (chkerp != null && chkerp.PONumber == poNumber)
            {
                MessageBox.Show("This Po#" + " " + poNumber + " " + "is registered already");
            }
            else
            {
                //check for po in rms
                var chrmspo = Rmsdb.PurchaseOrders.Where(p => p.PONumber == poNumber).FirstOrDefault();


                if (chrmspo != null && poNumber == chrmspo.PONumber)
                {
                    
                    MessageBox.Show("PO#" + " " + poNumber + " " + "Found in the database, would you like to register this PO#");

                    Por.PONumber = poNumber;
                    Por.Type = 1;
                    Por.CreatedBy = "Import";
                    Por.CreateDate = DateTime.Today.Date;
                    Por.UpdateBy = "Import";
                    Por.UpdateDate = DateTime.Today.Date;

                    var supl = (from s in Rmsdb.Suppliers
                                join p in Rmsdb.PurchaseOrders on s.ID equals p.SupplierID
                                where p.PONumber == poNumber
                                select new { s.SupplierName }).FirstOrDefault();

                    Por.SupplierContact = supl.SupplierName;
                    Por.Active = true;
                    crmdb.t_PO_Register.Add(Por);
                    crmdb.SaveChanges();

                    MessageBox.Show("Registered successfuly.");

                }
                else
                {
                    MessageBox.Show("PO#" + " " + poNumber + " " + "Does not Exist in RMS database and can't be register");
                }
            }

Open in new window

LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
You didn't mentioned anything about the database...have you checked the settings if your data are case sensitive....e.g MySQL on Linux has this as default.
0
Moti Mashiah.NET DeveloperAuthor Commented:
My database is Microsoft SQL and there is no case sensitive.
0
Moti Mashiah.NET DeveloperAuthor Commented:
Microsoft SQL 2012
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Moti Mashiah.NET DeveloperAuthor Commented:
Actually, I did - ToUpper(); method and it fixed the issue, but if you have some other suggestion I will be happy to have.
0
it_saigeDeveloperCommented:
A case insensitive check would look something like:
//check po in erp system
var chkerp = crmdb.t_PO_Register.FirstOrDefault(p => string.Equals(p.PONumber, poNumber, StringComparison.OrdinalIgnoreCase);

Open in new window

OR
//check po in erp system
var chkerp = crmdb.t_PO_Register.FirstOrDefault(p => string.Compare(p.PONumber, poNumber, true, CultureInfo.CurrentCulture) == 0);

Open in new window

Proof of concept -
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace EE_Q28690990
{
	class Program
	{
		static List<Person> people = new List<Person>() 
		{ 
			new Person() { ID = 1, Name = "Jim", Gender = Gender.Male }, 
			new Person() { ID = 2, Name = "Julie", Gender = Gender.Female }, 
			new Person() { ID = 3, Name = "Peter", Gender = Gender.Male }, 
			new Person() { ID = 4, Name = "Patricia", Gender = Gender.Female }, 
			new Person() { ID = 5, Name = "Vance", Gender = Gender.Male }, 
			new Person() { ID = 6, Name = "Vanessa", Gender = Gender.Female } 
		};

		static void Main(string[] args)
		{
			var p1 = people.FirstOrDefault(person => string.Equals(person.Name, "vanessA", StringComparison.OrdinalIgnoreCase));
			if (p1 != null)
			{
				Console.WriteLine();
				Console.WriteLine("Found vanessA in the list:");
				Console.WriteLine("{0} [{1}] is a {2}", p1.Name, p1.ID, p1.Gender);
			}

			p1 = people.FirstOrDefault(person => string.Compare(person.Name, "pAtRiCiA", true, CultureInfo.CurrentCulture) == 0);
			if (p1 != null)
			{
				Console.WriteLine();
				Console.WriteLine("Found pAtRiCiA in the list:");
				Console.WriteLine("{0} [{1}] is a {2}", p1.Name, p1.ID, p1.Gender);
			}

			Console.ReadLine();
		}
	}

	class Person
	{
		public int ID { get; set; }
		public string Name { get; set; }
		public Gender Gender { get; set; }
	}

	enum Gender : int
	{
		None = 0,
		Male = 1,
		Female = 2,
		Unknown = 3,
		Undeclared = 4
	}
}

Open in new window

Produces the following output -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moti Mashiah.NET DeveloperAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.