I'm using what I consider to be very standard C# and T-SQL code to populate a column of datatype char(1)
based on a C# enum
with char
values :
I am seeing an asterisk *
written to db when a C
should be written -- but I have been unable to find a consistent repo and I have no idea how this could happen.
Some questions are how could a row be inserted into my db that includes a value not present in my enum ? Does the asterisk have any special meaning in this context ?
Here's representative code - stripped-down for readability :
CREATE TABLE [MY_TABLE](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[STATUS] [char](1) NOT NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
CREATE PROCEDURE [INSERT_TO_MY_TABLE]
(
@status [char](1)
)
AS
BEGIN
INSERT INTO [MY_TABLE]
(
[STATUS]
)
VALUES
(
@status
)
END
public enum Status
{
Adult = 'A',
Juvenile = 'J',
Child = 'C'
}
Statu status = Status.Child;
using (var command = connection.CreateCommand())
{
command.CommandText = $"INSERT_TO_MY_TABLE";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter($"@status", (char)status));
command.ExecuteNonQuery();
}