if (ds.Tables["Producers"].Rows.Count > 1)to this:
if (ds.Tables["Producers"].Rows.Count > position)
~~Bonnie>public partial class Producer : Form > { > DataRow m_Row; > public Producer(DataRow row, int position) > { > m_Row = row; > this.BindingContext[m_Row.Table].Position = position; > InitializeComponent(); > } > > > private void btnClose_Click(object sender, EventArgs e) > { > m_Row.RejectChanges(); > this.Close(); > } > > > private void Producer_Load(object sender, EventArgs e) > { > this.txtFirstName.DataBindings.Add("Text", m_Row.Table, "FirstName"); > this.txtLastName.DataBindings.Add("Text", m_Row.Table, "LastName"); > this.txtLicenseNumber.DataBindings.Add("Text", m_Row.Table, "LicenseNumber"); > this.txtAppointmentDate.DataBindings.Add("Text", m_Row.Table, "AppointmentDate"); > this.chkActive.DataBindings.Add("Checked", m_Row.Table, "Active"); > } > > > private void btnOK_Click(object sender, EventArgs e) > { > // Here change first name and I return back to my Agency Form > this.Close(); > } > >} >>
>private void btnProducerEdit_Click(object sender, EventArgs e) > { > int i = grdProducers.CurrentRow.Index; > DataRow row = dsProducers.Tables["Producers"].DefaultView[i].Row; > Producer frmProducers = new Producer(row, i); > frmProducers.Text = "Producers"; > frmProducers.ShowDialog(); > // Update producer if there are changes > if (dsProducers.HasChanges()) > { > CustomerBiz oCustomerBiz = new CustomerBiz(); > DataSet ds; > ds = dsProducers.GetChanges(); > oCustomerBiz.UpdateCustomer(dsProducers, i); > } >} >>
>public class CustomerDA > { > string connectionstring = Properties.Settings.Default.myconnstring; > public void UpdateCustomer(DataSet ds, int position) > { > string myname; > string userid; > SqlConnection cn = new SqlConnection(this.connectionstring); > cn.Open(); > if (ds.Tables["Producers"].Rows.Count > 1) > { > DataRow dr; > dr = ds.Tables["Producers"].Rows[position]; > myname = dr["FirstName"].ToString(); > userid = dr["userid"].ToString(); > SqlCommand sc = new SqlCommand(); > sc.CommandType = CommandType.StoredProcedure; > sc.Connection = cn; > sc.CommandText = "SaveCRMCustomerProducer"; > sc.Parameters.AddWithValue("@UserID", userid); > sc.Parameters.AddWithValue("@FirstName", myname); > sc.ExecuteNonQuery(); > } > > cn.Close(); > } > } > >>