DataAdapter.Update

  • Thread starter Thread starter David D. McCrory
  • Start date Start date
D

David D. McCrory

Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);
 
David,
First of all, if you use webservice as remote service for your dataset you
do not have to send dataset manually as XML. Dataset object implements
serialization of its state into XML, so simply submit Dataset object. One
note, It is recommended you use Typed Dataset.

Second, in order to send updates use:

Dim changedDS as Dataset = currentDS.GetChanges()

submit changed dataset to the server and it will execute required CRUD
operations via Data Adapter. It is not necessary to manage connection object
manually while using Data Adapter, it managed it internally.

I am working on the long post for Optimistic Concurrency which is going to
cover what you are trying to do, check my site in a few days.

I hope this helps, Maxim

[www.ipattern.com do you?]
 
Hi Maxim,

Just to add a comment:
Datasets are quite large when serialized, thus you might prefer an explicit
method of serializing (it gives you an oppurtunity of zipping it before
sending over the network...)

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Maxim V. Karpov said:
David,
First of all, if you use webservice as remote service for your dataset you
do not have to send dataset manually as XML. Dataset object implements
serialization of its state into XML, so simply submit Dataset object. One
note, It is recommended you use Typed Dataset.

Second, in order to send updates use:

Dim changedDS as Dataset = currentDS.GetChanges()

submit changed dataset to the server and it will execute required CRUD
operations via Data Adapter. It is not necessary to manage connection object
manually while using Data Adapter, it managed it internally.

I am working on the long post for Optimistic Concurrency which is going to
cover what you are trying to do, check my site in a few days.

I hope this helps, Maxim

[www.ipattern.com do you?]


David D. McCrory said:
Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
That is why I was wanting to pass a string instead of a DataSet....is this
the proper way to continue??


Miha Markic said:
Hi Maxim,

Just to add a comment:
Datasets are quite large when serialized, thus you might prefer an explicit
method of serializing (it gives you an oppurtunity of zipping it before
sending over the network...)

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Maxim V. Karpov said:
David,
First of all, if you use webservice as remote service for your dataset you
do not have to send dataset manually as XML. Dataset object implements
serialization of its state into XML, so simply submit Dataset object. One
note, It is recommended you use Typed Dataset.

Second, in order to send updates use:

Dim changedDS as Dataset = currentDS.GetChanges()

submit changed dataset to the server and it will execute required CRUD
operations via Data Adapter. It is not necessary to manage connection object
manually while using Data Adapter, it managed it internally.

I am working on the long post for Optimistic Concurrency which is going to
cover what you are trying to do, check my site in a few days.

I hope this helps, Maxim

[www.ipattern.com do you?]


David D. McCrory said:
Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet
from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
Both ways are OK IMO.
Depends on your needs though.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

David D. McCrory said:
That is why I was wanting to pass a string instead of a DataSet....is this
the proper way to continue??


Miha Markic said:
Hi Maxim,

Just to add a comment:
Datasets are quite large when serialized, thus you might prefer an explicit
method of serializing (it gives you an oppurtunity of zipping it before
sending over the network...)

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

dataset
you
going
to
cover what you are trying to do, check my site in a few days.

I hope this helps, Maxim

[www.ipattern.com do you?]


Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record
that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of
passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the
WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
This may seem like a basic question, but please bear with me....

When I use the GetXml() function, I pass a string to the WebService. What
will I be passing to the WebService if I use the example you have listed??


Miha Markic said:
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

David D. McCrory said:
Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
Hi David,

sb.ToString() will give you a string.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

David D. McCrory said:
This may seem like a basic question, but please bear with me....

When I use the GetXml() function, I pass a string to the WebService. What
will I be passing to the WebService if I use the example you have listed??


Miha Markic said:
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

David D. McCrory said:
Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet
from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
I am sorry to keep bothering you with this issue.This will be my last post
for this. I have modified the code as you suggested and I am getting an
object error: "Object reference not set to an instance of an object".
Please review my code and see if you can spot what I am doing wrong. I also
tried the DataSet approach and still got a new record instead of modifying
the existing record.


Web Page Code
private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
if (dsUserInfo.Tables["UserInfo"].Rows.Count > 0)
{
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
}
dsUserInfo.WriteXml(sw, XmlWriteMode.DiffGram);
cmi.UpdateUserInfo(sb.ToString()); ------------>This is the call to my
webservice
//cmi.UpdateUserInfo(dsUserInfo.GetXml());
BindUserInfo();
}

WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataRow dr;
DataSet ds = new DataSet();
//Load the DataSet with the XML string.
ds.ReadXml(new StringReader(info));
//Iterate through the Rows.
for (int i = 0; i < ds.Tables["UserInfo"].Rows.Count; i++)
{
dr = ds.Tables["UserInfo"].Rows;
//Strip any extra characters from the Social Security Number.
dr["SSNumber"] =
suf.StripFromNumberString(dr["SSNumber"].ToString());
}
//Update the database with any changes.
daUserInfo.Update(ds, "UserInfo");
}


Miha Markic said:
Hi David,

sb.ToString() will give you a string.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

David D. McCrory said:
This may seem like a basic question, but please bear with me....

When I use the GetXml() function, I pass a string to the WebService. What
will I be passing to the WebService if I use the example you have listed??


Miha Markic said:
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record
that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update() function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of
passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the
WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
Hi David,

No problem. Just keep posting.
Which line does cause the exception?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

David D. McCrory said:
I am sorry to keep bothering you with this issue.This will be my last post
for this. I have modified the code as you suggested and I am getting an
object error: "Object reference not set to an instance of an object".
Please review my code and see if you can spot what I am doing wrong. I also
tried the DataSet approach and still got a new record instead of modifying
the existing record.


Web Page Code
private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
if (dsUserInfo.Tables["UserInfo"].Rows.Count > 0)
{
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
}
dsUserInfo.WriteXml(sw, XmlWriteMode.DiffGram);
cmi.UpdateUserInfo(sb.ToString()); ------------>This is the call to my
webservice
//cmi.UpdateUserInfo(dsUserInfo.GetXml());
BindUserInfo();
}

WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataRow dr;
DataSet ds = new DataSet();
//Load the DataSet with the XML string.
ds.ReadXml(new StringReader(info));
//Iterate through the Rows.
for (int i = 0; i < ds.Tables["UserInfo"].Rows.Count; i++)
{
dr = ds.Tables["UserInfo"].Rows;
//Strip any extra characters from the Social Security Number.
dr["SSNumber"] =
suf.StripFromNumberString(dr["SSNumber"].ToString());
}
//Update the database with any changes.
daUserInfo.Update(ds, "UserInfo");
}


Miha Markic said:
Hi David,

sb.ToString() will give you a string.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

David D. McCrory said:
This may seem like a basic question, but please bear with me....

When I use the GetXml() function, I pass a string to the WebService. What
will I be passing to the WebService if I use the example you have listed??


"Miha Markic" <miha at rthand com> wrote in message
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record
that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update()
function,
the record is inserted as a new record instead of modifying the existing
record. I wanted to pass the XML string to the WebService instead of
passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the
WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}
 
It appears to be failing on the highlighted code....There does not appear to be a "UserInfo" table.

[WebMethod]
public void UpdateUserInfo(string info)
{
DataRow dr;
DataSet ds = new DataSet();
//Load the DataSet with the XML string.
ds.ReadXml(new StringReader(info));
//Iterate through the Rows.
for (int i = 0; i < ds.Tables["UserInfo"].Rows.Count; i++) <--------------Code fails here.........
{
dr = ds.Tables["UserInfo"].Rows;
//Strip any extra characters from the Social Security Number.
dr["SSNumber"] =
suf.StripFromNumberString(dr["SSNumber"].ToString());
}
//Update the database with any changes.
daUserInfo.Update(ds, "UserInfo");
}

Miha Markic said:
Hi David,

No problem. Just keep posting.
Which line does cause the exception?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

David D. McCrory said:
I am sorry to keep bothering you with this issue.This will be my last post
for this. I have modified the code as you suggested and I am getting an
object error: "Object reference not set to an instance of an object".
Please review my code and see if you can spot what I am doing wrong. I also
tried the DataSet approach and still got a new record instead of modifying
the existing record.


Web Page Code
private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
if (dsUserInfo.Tables["UserInfo"].Rows.Count > 0)
{
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
}
dsUserInfo.WriteXml(sw, XmlWriteMode.DiffGram);
cmi.UpdateUserInfo(sb.ToString()); ------------>This is the call to my
webservice
//cmi.UpdateUserInfo(dsUserInfo.GetXml());
BindUserInfo();
}

WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataRow dr;
DataSet ds = new DataSet();
//Load the DataSet with the XML string.
ds.ReadXml(new StringReader(info));
//Iterate through the Rows.
for (int i = 0; i < ds.Tables["UserInfo"].Rows.Count; i++)
{
dr = ds.Tables["UserInfo"].Rows;
//Strip any extra characters from the Social Security Number.
dr["SSNumber"] =
suf.StripFromNumberString(dr["SSNumber"].ToString());
}
//Update the database with any changes.
daUserInfo.Update(ds, "UserInfo");
}


Miha Markic said:
Hi David,

sb.ToString() will give you a string.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

This may seem like a basic question, but please bear with me....

When I use the GetXml() function, I pass a string to the WebService. What
will I be passing to the WebService if I use the example you have listed??


"Miha Markic" <miha at rthand com> wrote in message
Hi David,

This is by design.
Instead use something WriteXml method:
StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

dataSet1.WriteXml(sw, XmlWriteMode.DiffGram);


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hello Group,

I am trying to use the Data Adapter.Update() function. I have a record
that
has been modified that I am passing to a WebService using the
DataSet.GetXml() function. When I call the DataAdapter.Update()
function,
the record is inserted as a new record instead of modifying the
existing
record. I wanted to pass the XML string to the WebService instead of
passing
a DataSet. So I have 2 questions for the group:

1.How can I pass the XML and retain the status of the records?
2. Shouldn't the Update function compare the record in the DataSet
from
the
WebService to the DataSource and update the existing row??

Here is the code from the Web Page followed by the code from the
WebService


Web Page Code

private void lnkbtnUpdate_Click(object sender, System.EventArgs e)
{
DataRow dr;
Global app = (Global) Context.ApplicationInstance;
//Load the DataSet.
dsUserInfo = app.LoadDataSet("UserInfo", 0);
//Get the current data row.
dr = dsUserInfo.Tables["UserInfo"].Rows[0];
//Set the values equal to the screen values.
dr["FirstName"] = txtFirstName.Text;
dr["MiddleName"] = txtMName.Text;
dr["LastName"] = txtLastName.Text;
dr["SSNumber"] = txtSSNumber.Text;
dr["DateofBirth"] = txtBirthDate.Text;
dr["Gender"] = ddlGender.SelectedValue;
//Call the WebService and pass the updated information.
cmi.UpdateUserInfo(dsUserInfo.GetXml());
}


WebService Code

[WebMethod]
public void UpdateUserInfo(string info)
{
DataSet ds = new DataSet();
ds.ReadXml(new StringReader(info));
try
{
cnCrewManagement.Open();
daUserInfo.Update(ds, "UserInfo");
}
finally
{
cnCrewManagement.Close();
}
}

 
Hi David,

Are you shure that there is a UserInfo table?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

It appears to be failing on the highlighted code....There does not appear to
be a "UserInfo" table.

[WebMethod]
public void UpdateUserInfo(string info)
{
DataRow dr;
DataSet ds = new DataSet();
//Load the DataSet with the XML string.
ds.ReadXml(new StringReader(info));
//Iterate through the Rows.
for (int i = 0; i < ds.Tables["UserInfo"].Rows.Count; i++)
<--------------Code fails here.........
{
dr = ds.Tables["UserInfo"].Rows;
//Strip any extra characters from the Social Security Number.
dr["SSNumber"] =
suf.StripFromNumberString(dr["SSNumber"].ToString());
}
//Update the database with any changes.
daUserInfo.Update(ds, "UserInfo");
}
 
It works when I send it with the GetXml() function.......I didn't change any
of the code on the WebService side, just the client code was modified with
your suggestion......
 
Back
Top