Your method is static
.. your variable is not.
You need to mark your variable as static
for it to be used in static
methods:
public static int CarrierID { get; set; }
// ^^^^^^ this
The other option you have is to remove the static
modifier from the method this code is in and instantiate the class it is in before using it.
EDIT:
After your edit.. I think you should change your method to this:
public static List<EmpData> GetData(int carrierId) {
// code here..
cmd.Parameters.AddWithValue("CarrierID", carrierId);
// code here..
}
Then, whenever you call it.. pass in the CarrierID
you need:
EmpData.GetData(5);
I assume you already have the required CarrierID
available and set.. prior to calling this method (so you can pass it in). I also uppercased the first character of the method.. since that is more in line with C# style.