i have a textbox which have a decimal value 0.5.
this code to enable or disable the textbox.enable textbox to put 0.5 in the textbox.
when the textbox is disabled value null should be inserted in the database tablle
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (!checkBox1.Checked)
{
textBox4.Enabled = false;
}
else
{
textBox4.Enabled = true;
}
}
this code for inserting both null or 0.5 value from the textbox
SqlParameter pIn;
if (checkBox1.Checked == true)
{
decimal half = Convert.ToDecimal(textBox4.Text);
command.Parameters.Add("@HalfDay", SqlDbType.Decimal).Value = half;
textBox4.Text = String.Format("{0:0.0}", half);
}
else
if (checkBox1.Checked == false)
{
if (String.IsNullOrEmpty(textBox4.Text))
{
pIn = command.Parameters.Add("@HalfDay", SqlDbType.Decimal);
pIn.Precision = 18;
pIn.Scale = 2;//string s = Convert.ToString(radioButton2.Text);
pIn.Value = DBNull.Value;
}
}
i can insert 0.5 via textbox but unable to insert null.
emmy