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 kumarPosted Feb 16, 2010, 11:01 AM
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");
}
}
}
}
kiran kumarPosted Feb 16, 2010, 9:58 PM
check the answer if it helped you
Rashid KhanPosted Feb 16, 2010, 1:08 PM
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
paul danielPosted Feb 16, 2010, 2:23 AM
http://www.javascript-coder.com/html-form/html-form-submit.phtml?mysubmit=Click!
Lalit MPosted Feb 16, 2010, 1:32 AM
Lalita PeddiPosted Feb 16, 2010, 12:32 AM
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
villiPosted Feb 15, 2010, 2:11 PM
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