Hi!!
how to delete a record in database by getting value through inputbox ???eg: there are 3 records lyk a, b, c
am gonna delete b, if i click delete button an input box should ask enter id:____
then i should enter the id after that record(b) in database should get deleted...
Satyapriya NayakPosted Mar 26, 2013, 5:30 AM
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.OleDb;
namespace Textbox_data_Delete_in_windows
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void btn_delete_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please insert data");
}
else
{
try
{
OleDbConnection con = new OleDbConnection(ConnectionString);
str = "Delete from emp where name='" + textBox1.Text + "'";
com = new OleDbCommand(str, con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
MessageBox.Show("Would you like to delete?", "Deleting Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Question);
textBox1.Text = "";
}
}
}
}
AbhiPriya M VPosted Mar 26, 2013, 6:15 AM