hi to all
how to add, delete and update the datagridview control in windows application.
don't use textbox and label. datagridview control in changed in edit delete and add the database fields.
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 attend5days leftRegister
Praveen N104 reputationPosted Dec 22, 2013, 6:51 PM EST
public partial class DataTrialForm : 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 DataTrialForm() { InitializeComponent(); } private void DataTraiForm_Load(object sender, EventArgs e) { sqlConnection = new SqlConnection("data source=SEZ-WS-137\\SQLEXPRESS2008;initial catalog=AttendanceData;user id=sa;password=pass"); selectQueryString = "select top 20 * from Attendance order by punchtime asc"; sqlConnection.Open(); sqlDataAdapter = new SqlDataAdapter(selectQueryString, sqlConnection); sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter); dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); bindingSource = new BindingSource(); bindingSource.DataSource = dataTable; dataGridViewTrial.DataSource = bindingSource; // to hide Identity column dataGridViewTrial.Columns[0].Visible = false; } private void addUpadateButton_Click(object sender, EventArgs e) { try { sqlDataAdapter.Update(dataTable); } catch (Exception exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); } } private void deleteButton_Click(object sender, EventArgs e) { try { dataGridViewTrial.Rows.RemoveAt(dataGridViewTrial.CurrentRow.Index); sqlDataAdapter.Update(dataTable); } catch (Exception exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); } } } Thanks & Regards, Praveen NelgePraveen N104 reputationPosted Dec 22, 2013, 6:53 PM EST
http://www.mindstick.com/Articles/9422cfc8-c2ed-4ec1-9fab-589eb850a863/?Insert%20Delete%20Update%20in%20Da
Thanks & Regards,
Praveen N