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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 10:22 PM EDT
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
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 9:45 PM EDT
In winform, you can't enter date value manually in datetime picker. Are you asking in ASP.NET?
Regards,
Iftikar
ta mu198 reputationPosted Aug 20, 2013, 9:48 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 9:51 PM EDT
ta mu198 reputationPosted Aug 20, 2013, 10:04 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 10:05 PM EDT
ta mu198 reputationPosted Aug 20, 2013, 10:12 PM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 10:12 PM EDT
ta mu198 reputationPosted Aug 20, 2013, 10:17 PM EDT
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; }
ta mu198 reputationPosted Aug 20, 2013, 10:45 PM EDT
have warning
Warning 1 Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 20, 2013, 11:06 PM EDT
Uchiha Itachi40 reputationPosted Dec 2, 2013, 10:24 PM EST
GridComboBoxColumn supplierColumn = new GridComboBoxColumn(); supplierColumn.Name = "PorductsColumn"; supplierColumn.HeaderText = "Porducts"; supplierColumn.DataSource = this.porductsBindingSource; supplierColumn.ValueMember = "PorductID"; supplierColumn.DisplayMember = "PorductName"; supplierColumn.FieldName = "PorductsID"; supplierColumn.Width = 150; this.ketticGridView1.Columns.Add(supplierColumn);