Dear friends
thanx for your kind support on dropdown list issue,
now i need to know can i set 2 event on the 1 button in form?
i mean i have a form with few field and having only one button.
so how can i set that when user select insert option then under this menu this button work for insert function and when user select update option is works update function.
please let me know how to set it
Thanks in advance
Loading

kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 6:01 AM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace dropinsert
{
public partial class Form1 : Form
{
string[] values = { "insert", "update" };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < values.Length; i++)
{
comboBox1.Items.Add(values[i]);
}
this.button1.Click += new EventHandler(hi);
}
private void hi(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() == "insert")
{
SqlConnection con = new SqlConnection("Data Source=kiran\\sqlexpress;Initial Catalog=kiran;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("insert into inup(sd)values(@sd)", con);
SqlParameter s = new SqlParameter("@sd", SqlDbType.NVarChar, 50);
s.Value = comboBox1.SelectedItem.ToString();
cmd.Parameters.Add(s);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("inserted suc");
}
else
{
SqlConnection con = new SqlConnection("Data Source=kiran\\sqlexpress;Initial Catalog=kiran;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("update inup set sd='"+comboBox1.SelectedItem+"'",con);
cmd.ExecuteNonQuery();
MessageBox.Show("upt succ");
}
}
}
}
villi3 reputationPosted Feb 15, 2010, 9:11 AM EST
if user insert the data first & then user press the buton so
fisrt u can check that data like(id) in your data base,
if u find that value then call update function
else call the insert fuction
Lalita Peddi6 reputationPosted Feb 15, 2010, 7:32 PM EST
You can keep a flag to check which of the two options is selected and on click of the button, raise one event, which checks the value of the flag. Accordingly, you can call the separate methods in the same event.
Mark it as answer if it helps.
-Lalita
Lalit MRank #1,186 · 1.5K reputationPosted Feb 15, 2010, 8:32 PM EST
paul daniel189 reputationPosted Feb 15, 2010, 9:23 PM EST
http://www.javascript-coder.com/html-form/html-form-submit.phtml?mysubmit=Click!
Rashid Khan152 reputationPosted Feb 16, 2010, 8:08 AM EST
Thank you so much for you kind support.
i fixed my issue. in different way.
i set button text according to operation, nd on button event i check button text and set opereation on it by using If/Else
thanks once again,
Regards
Rashid
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 4:58 PM EST
check the answer if it helped you