SqlDataAdapter adp; SqlCommandBuilder cmdBld; DataTable dtEditMember = new DataTable(); private void butLoadMember_Click(object sender, EventArgs e) { using (SqlConnection conn = new SqlConnection(dbConn)) { conn.Open(); using (adp = new SqlDataAdapter()) { if (txtEditMemberVehiNo.MaskCompleted) { adp.SelectCommand = new SqlCommand("Select * From Master Where VehiNo = @VehiNo"); adp.SelectCommand.Parameters.Add("@VehiNo", SqlDbType.NVarChar).Value = txtEditMemberVehiNo.Text; } else if (!string.IsNullOrWhiteSpace(txtEditMemberCustName.Text)) { adp.SelectCommand = new SqlCommand("Select * From Master Where CustName = @CustName"); adp.SelectCommand.Parameters.Add("@CustName", SqlDbType.NVarChar).Value = txtEditMemberCustName.Text; } adp.SelectCommand.Connection = conn; adp.Fill(dtEditMember); } } if (dtEditMember.Rows.Count > 0) { dgvEditMember.DataSource = dtEditMember; dgvEditMember.Columns["VehiNo"].HeaderText = "Vehicle No"; butLoadMember.Enabled = false; butUpdateMember.Enabled = true; } else { txtEditMemberVehiNo.Clear(); txtEditMemberCustName.Clear(); dgvEditMember.Columns.Clear(); MessageBox.Show("Member Not Found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void butUpdateMember_Click(object sender, EventArgs e) { cmdBld = new SqlCommandBuilder(adp); if (dtEditMember.GetChanges() != null) { adp.Update(dtEditMember); MessageBox.Show("Changes Done."); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)