Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in my window application i am creating a datepicker and checkboxes. once i checked (yes) so some controls are becoming invisible.and records should be go to the datatable . if some controls are invisible after checked so data should be enter blank from datepickers.
i am sending my codes


if is there any example which is related to my codes so please forward to me.

What I have tried:

private void button1_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DCID;Integrated Security=True"))
{

// string query = "insert into SystemConfiguration(FRANo,ProductCategory,make,PartName,SerialNo,BriefDetails,invoiceNo,productCost,vandorName,warranty) values(@FRANo,@ProductCategory,@make,@PartName,@SerialNo,@BriefDetails,@invoiceNo,@warranty,@productCost,@vandorName)";
string query = "insert into SystemConfiguration(FRANo,ProductCategory,make,SerialNo,BriefDetails,invoiceNo,date,productCost,vandorName,warranty,warrantyUpTo,IssuedTo,IssuedOn,UnderAMC,AMCWith,AMCUpTo) values(@FRANo,@ProductCategory,@make,@SerialNo,@BriefDetails,@invoiceNo,@date,@productCost,@vandorName,@warranty,@warrantyUpTo,@IssuedTo,@IssuedOn,@underamc,@AMCWith,@AMCUpTo)";
SqlCommand cmd = new SqlCommand(query, con);

cmd.Parameters.AddWithValue("@FRANo", Int32.Parse(txtfrano.Text));
cmd.Parameters.AddWithValue("@ProductCategory", comboproductcategory.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@make", combomake.SelectedItem.ToString());
// cmd.Parameters.AddWithValue("@PartName", combopartname.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@SerialNo", txtserialno.Text);
cmd.Parameters.AddWithValue("BriefDetails", txtbriefConfiguration.Text);
cmd.Parameters.AddWithValue("@invoiceNo", Int32.Parse(txtinvoicno.Text));
cmd.Parameters.AddWithValue("@date", Convert.ToDateTime(dateTimePickerdate.Text));
cmd.Parameters.AddWithValue("@productCost", Convert.ToDecimal(txtproductcost.Text));
cmd.Parameters.AddWithValue("@vandorName", txtvendorname.Text);


string ss = "Empty";


if (checkBoxOnsite.Checked)
{
cmd.Parameters.AddWithValue("@warranty", warranty);


DateTimePicker objpick = new DateTimePicker();
objpick.Name = "black";
string ss1 = objpick.Name;
cmd.Parameters.AddWithValue("@warrantyUpTo", Convert.ToString(ss1));

cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToString(ss1));
cmd.Parameters.AddWithValue("@AMCWith", ss);


}
else if (!checkBoxOnsite.Checked)
{

cmd.Parameters.AddWithValue("@warranty", ss);

cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToDateTime(dateTimeWarrantyUpTo.Text));

cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToDateTime(dateTimeAMCupTo.Text));
cmd.Parameters.AddWithValue("@AMCWith", texAMCWith.Text);

}


if (checkBoxunderamcyes.Checked)
{

cmd.Parameters.AddWithValue("@UnderAMC", underamc);
}
else if (!checkBoxunderamcyes.Checked)
{

cmd.Parameters.AddWithValue("@UnderAMC", ss);
}






//cmd.Parameters.AddWithValue("@UnderAMC", underamc);


cmd.Parameters.AddWithValue("@IssuedTo", Convert.ToDateTime(dateTimeIssuedTo.Text));
cmd.Parameters.AddWithValue("@IssuedOn", Convert.ToDateTime(dateTimeIssuedON.Text));




SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();


da.Fill(dt);
MessageBox.Show("Submit");
clearAll();
}

}
catch (Exception ex)
{

MessageBox.Show("Check Again !"+ex.Message+"");

}


}

private void checkBoxOnsite_CheckedChanged(object sender, EventArgs e)
{
warranty = "On Site";
if (checkBoxOnsite.Checked)
{
checkBoxunderamcyes.Enabled = false;
checkBoxunderamcno.Enabled = false;
checkBoxunderamcyes.Checked = false;
checkBoxOffsite.Enabled = false;
dateTimeAMCupTo.Enabled = false;
texAMCWith.Enabled = false;
dateTimeWarrantyUpTo.Enabled = false;
}
else if (!checkBoxOnsite.Checked)
{

checkBoxunderamcyes.Enabled = true;
checkBoxunderamcyes.Checked = false;
checkBoxOffsite.Enabled = true;
dateTimeAMCupTo.Enabled = true;
texAMCWith.Enabled = true;
dateTimeWarrantyUpTo.Enabled = true;
}
}
Posted
Updated 24-Feb-16 4:04am
Comments
ZurdoDev 24-Feb-16 7:58am    
Where are you stuck? What you described is a little confusing but doesn't seem like it would be hard.

1 solution

Hi Faizyb,

Please try this one
cmd.Parameters.AddWithValue("@warrantyUpTo", DBNull.Value);
 
Share this answer
 
Comments
faizyab 2009 25-Feb-16 3:53am    
Thank you so much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900