Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataGridView
Message
From
09/11/2007 12:46:44
 
 
To
09/11/2007 09:24:06
General information
Forum:
ASP.NET
Category:
Forms
Title:
Environment versions
Environment:
C# 2.0
OS:
Vista
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01267049
Message ID:
01267996
Views:
10
This message has been marked as a message which has helped to the initial question of the thread.
Sergio,

See Message #1265584.

Also, I'd change one line in your UpdateCustomer() method in your DataAccess class and that is:

Change this:
if (ds.Tables["Producers"].Rows.Count > 1)
to this:
if (ds.Tables["Producers"].Rows.Count > position)
~~Bonnie




>Hello Bonnie, I was able to save my DataSet but there is something that I guess I am doing wrong. ( I am changing only firstname just for testing ).
>
>The dsProducers.HasChanges DataSet returns false!!. But I did change some data on the Producer form:
>
>Here is my code on the Producer form :
>
>
>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();
>   }
>
>}
>
>
>
>Here is the code once I get back from producer form.
>dsProducers.HasChanges() is false???? :
>
>
>
>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);
>     }
>}
>
>
>As you can see I call my UpdateCustomer method and I pass it my DataSet and the currrent row index in order to update the row in my database.
>Here is my code in my DataAccess layer :
>
>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();
>     }
> }
>
>
>
>I know probably I am doing it the wrong way but since my dsProducers.HasChanges() is not reflecting changes I pass the row index to my method.
>
>
>Thanks
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform