Hi,
currently,I am developing windows applications.in my form i am having one gridview,one update and delete button .if the user directly selects the buttons .it has to show the message as "please select value from grid".how can i do this.please do the needful.
public partial class UpdateProduct : Form
{
private string connectionString = null;
private SqlConnection sqlConnection = null;
private SqlDataAdapter sqlDataAdapter = null;
private SqlCommandBuilder sqlCommandBuilder = null;
private DataTable dataTable = null;
private BindingSource bindingSource = null;
private string selectQueryString = null;
public UpdateProduct()
{
InitializeComponent();
}
private void UpdateProduct_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
selectQueryString = "select * from tbl_product";
conn.Open();
sqlDataAdapter = new SqlDataAdapter(selectQueryString, conn);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter );
dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dataGridView1.DataSource = bindingSource;
}
private void btnupdate_Click(object sender, EventArgs e)
{
try
{
sqlDataAdapter.Update(dataTable);
MessageBox.Show("Updated Successfully");
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
}
private void btndelete_Click(object sender, EventArgs e)
{
try
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
sqlDataAdapter.Update(dataTable);
MessageBox.Show("Are you Sure Want To Delete This Row?", "DeleteConformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}
catch (Exception exceptionObj)
{
MessageBox.Show(exceptionObj.Message.ToString());
}
}
}
}
Best,
Sudheep.