I have a subroutine to insert a record to sql server table.
The code:
public void Insert_Met(int Counts, char Gender)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("@Counts", Counts);
parameters.Add("@Gender", Gender);
// run a stored procedure ExecuteNonQuery
}
I other line code,
int counts = Convert.ToInt32(numberUpdowncontrol1.Text);
// from a control, maybe empty then it is null.
Insert_Met(counts,'M');
My question is sometimes Counts can be null, so how to change my code?
Thanks,
You could use
int? countsinstead ofint counts, and check the value within your method:In order to set the count value appropriately for the above, you could do: