SqlDataAdapter.Update doesn't update

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hi,

In ASP.NET, i've got a web forms app, which does its data operations
through a middleware DataManager dll.

In one operation, the web form creates a types dataset from a stored
schema, adds a DataRow to the single DataTable object and passes this
to the dll for upload.

---begin webform function---

{
ForumData fData = new ForumData();
PeopleDataSet pds = new PeopleDataSet();
DataTable dt = pds.Tables["People"];
DataRow dr = dt.NewRow();
dr["PeopleID"] = Convert.ToInt32(this.txtPeopleID.Text);
dr["Name"] = this.txtName.Text;
dr["Email"] = this.txtEmail.Text;
dr["Password"] = this.txtPassword.Text;
dr["Sig"] = this.txtSig.Text;
dr["ShowDetail"] = Convert.ToBoolean(this.txtShowDetail.Text);
dr["Photo"] = Convert.ToBoolean(this.txtPhoto.Text);
dr["PicApprove"]= Convert.ToBoolean(this.txtPicApprove.Text);
dr["MemberApprove"] = Convert.ToBoolean(this.txtMemberApprove.Text);
dr["PlainText"] = Convert.ToBoolean(this.txtPlainText.Text);
dr["DOB"] = Convert.ToDateTime(this.txtDOB.Text);
dr["LastHere"] = Convert.ToDateTime(this.txtLastHere.Text);
dr["SignedUp"] = Convert.ToDateTime(this.txtSignedUp.Text);
dr["CountPosts"] = Convert.ToInt32(this.txtCountPosts.Text);
dr["Title"] = this.txtTitle.Text;
dr["AvatarID"] = Convert.ToInt32(this.txtAvatarID.Text);
pds.Tables["People"].Rows.Add(dr);
bool testval = fData.AlterPersonDetails(pds);
//pds.WriteXml("c:\\pdsdataset.xml");
if (testval)
{
btnChange.Text = "Success";
}
else
{
btnChange.Text = "Failed";
}
}
-- end webform function ----

That gets passed to the Public method, AlterPersonDetails, which is,
naturally, just a passthrough to a private function

--- begin Public Method ---
public bool AlterPersonDetails(DataSet dsChangedPerson)
{
bool nValue = false;
try
{
nValue = ChangePersonDetails(dsChangedPerson);
}
catch
{
nValue = false;
}
return nValue;
}

--- end Public Method ---

Now, you'll note that i've taken the precaution of writing the DataSet
XML to a file in order to check that it does indeed change. It does.
Here's the problem. When mAdapter.Update is called, it doesn't appear
to do anything at all.

--- begin private function ---

private bool ChangePersonDetails(DataSet dsChangedPerson)
{
bool returnval;
SqlConnection mCon = MakeConn();
DataSet dsPeople = new XPeopleDataset();
mCon.Open();
SqlDataAdapter mAdapter = new SqlDataAdapter("SELECT * FROM People",
mCon);
SqlCommandBuilder mComm = new SqlCommandBuilder(mAdapter);
mAdapter.Fill(dsPeople, "People");
dsPeople.Merge(dsChangedPerson.Tables["People"]);
dsPeople.AcceptChanges();
dsPeople.WriteXml("C:\\xmlversion.xml");
int g = mAdapter.Update(dsPeople, "People");
mCon.Close();
returnval = true;
return returnval;
}

--- end private function ---

So, there's my problem. No exceptions, no problems and no changes to
the database! If anyone can help, I'd really appreciate it,
 
Hi Rich,

Your problem is that you are calling AcceptChanges before Update method
(AcceptChanges just consolidates dataset's rows rowstatus)

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

Rich said:
Hi,

In ASP.NET, i've got a web forms app, which does its data operations
through a middleware DataManager dll.

In one operation, the web form creates a types dataset from a stored
schema, adds a DataRow to the single DataTable object and passes this
to the dll for upload.

---begin webform function---

{
ForumData fData = new ForumData();
PeopleDataSet pds = new PeopleDataSet();
DataTable dt = pds.Tables["People"];
DataRow dr = dt.NewRow();
dr["PeopleID"] = Convert.ToInt32(this.txtPeopleID.Text);
dr["Name"] = this.txtName.Text;
dr["Email"] = this.txtEmail.Text;
dr["Password"] = this.txtPassword.Text;
dr["Sig"] = this.txtSig.Text;
dr["ShowDetail"] = Convert.ToBoolean(this.txtShowDetail.Text);
dr["Photo"] = Convert.ToBoolean(this.txtPhoto.Text);
dr["PicApprove"]= Convert.ToBoolean(this.txtPicApprove.Text);
dr["MemberApprove"] = Convert.ToBoolean(this.txtMemberApprove.Text);
dr["PlainText"] = Convert.ToBoolean(this.txtPlainText.Text);
dr["DOB"] = Convert.ToDateTime(this.txtDOB.Text);
dr["LastHere"] = Convert.ToDateTime(this.txtLastHere.Text);
dr["SignedUp"] = Convert.ToDateTime(this.txtSignedUp.Text);
dr["CountPosts"] = Convert.ToInt32(this.txtCountPosts.Text);
dr["Title"] = this.txtTitle.Text;
dr["AvatarID"] = Convert.ToInt32(this.txtAvatarID.Text);
pds.Tables["People"].Rows.Add(dr);
bool testval = fData.AlterPersonDetails(pds);
//pds.WriteXml("c:\\pdsdataset.xml");
if (testval)
{
btnChange.Text = "Success";
}
else
{
btnChange.Text = "Failed";
}
}
-- end webform function ----

That gets passed to the Public method, AlterPersonDetails, which is,
naturally, just a passthrough to a private function

--- begin Public Method ---
public bool AlterPersonDetails(DataSet dsChangedPerson)
{
bool nValue = false;
try
{
nValue = ChangePersonDetails(dsChangedPerson);
}
catch
{
nValue = false;
}
return nValue;
}

--- end Public Method ---

Now, you'll note that i've taken the precaution of writing the DataSet
XML to a file in order to check that it does indeed change. It does.
Here's the problem. When mAdapter.Update is called, it doesn't appear
to do anything at all.

--- begin private function ---

private bool ChangePersonDetails(DataSet dsChangedPerson)
{
bool returnval;
SqlConnection mCon = MakeConn();
DataSet dsPeople = new XPeopleDataset();
mCon.Open();
SqlDataAdapter mAdapter = new SqlDataAdapter("SELECT * FROM People",
mCon);
SqlCommandBuilder mComm = new SqlCommandBuilder(mAdapter);
mAdapter.Fill(dsPeople, "People");
dsPeople.Merge(dsChangedPerson.Tables["People"]);
dsPeople.AcceptChanges();
dsPeople.WriteXml("C:\\xmlversion.xml");
int g = mAdapter.Update(dsPeople, "People");
mCon.Close();
returnval = true;
return returnval;
}

--- end private function ---

So, there's my problem. No exceptions, no problems and no changes to
the database! If anyone can help, I'd really appreciate it,
 
Back
Top