i want to check
if combo box or datetimer picker selected value is empty show error enter the values.
how i can do this i dont know the correct formate.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Aug 21, 2013, 2:22 AM
private void button1_Click(object sender, EventArgs e)
{
if(ins_id.Text!="" && insaccountno.Text!="" && ins_no.Text!="" && insamount.Text!="" && comboBox1.SelectedValue!="")
{
SqlConnection my = new SqlConnection(@" Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\heaven_prince2009\Desktop\final pr latest\final pr\Database1.mdf;Integrated Security=True;User Instance=True");
my.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO add_installment (insid,insaccountno,ins_no,insamount,ins_status,date) VALUES ('" + insid.Text + "','" + insaccountno.Text + "','" + insno.Text + "','" + insamount.Text + "','" + comboBox1.SelectedValue + "','"+ ins_datetime.Value +"')", my);
cmd.ExecuteNonQuery(); MessageBox.Show("Data Inserted Successfully");
insid.Text = string.Empty;
insaccountno.Text = string.Empty;
insno.Text = string.Empty;
insamount.Text = string.Empty;
comboBox1.SelectedValue = string.Empty;
}
else
{
MessageBox.Show("enter the values");
}
}
Regards,
Iftikar
Uchiha ItachiPosted Dec 3, 2013, 3:24 AM
Iftikar HussainPosted Aug 21, 2013, 3:06 AM
ta muPosted Aug 21, 2013, 2:45 AM
have warning
Warning 1 Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
ta muPosted Aug 21, 2013, 2:17 AM
private void button1_Click(object sender, EventArgs e) { if (ins_id.Text==""||insaccountno.Text==""||ins_no.Text==""||insamount.Text==""||comboBox1.SelectedValue=="")
{ MessageBox.Show("enter the values"); } else { SqlConnection my = new SqlConnection(@" Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\heaven_prince2009\Desktop\final pr latest\final pr\Database1.mdf;Integrated Security=True;User Instance=True");
my.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO add_installment (insid,insaccountno,ins_no,insamount,ins_status,date) VALUES ('" + insid.Text + "','" + insaccountno.Text + "','" + insno.Text + "','" + insamount.Text + "','" + comboBox1.SelectedValue + "','"+ ins_datetime.Value +"')", my); cmd.ExecuteNonQuery(); MessageBox.Show("Data Inserted Successfully"); insid.Text = string.Empty; insaccountno.Text = string.Empty; insno.Text = string.Empty; insamount.Text = string.Empty; comboBox1.SelectedValue = string.Empty; }
Iftikar HussainPosted Aug 21, 2013, 2:12 AM
ta muPosted Aug 21, 2013, 2:12 AM
Iftikar HussainPosted Aug 21, 2013, 2:05 AM
ta muPosted Aug 21, 2013, 2:04 AM
Iftikar HussainPosted Aug 21, 2013, 1:51 AM
ta muPosted Aug 21, 2013, 1:48 AM
Iftikar HussainPosted Aug 21, 2013, 1:45 AM
In winform, you can't enter date value manually in datetime picker. Are you asking in ASP.NET?
Regards,
Iftikar