Hi,

I've bound a Datagrid to a Dataset, which works OK, however the update
isn't working correctly, I think the problem may be that

I am using a DataAdapter generated with a wizard with stored procedures
to select and update.

The binding code works OK, combining a number of tables into a single
table in a dataset and displaying it, here's the sp:

CREATE PROCEDURE proc_GetSampleAss
(@patientCode varchar(15),
@procedureDate datetime,
@usrNo int
)

AS

SELECT tblPatient.pntUnitID as 'Patient Code',
CONVERT(varchar, tblAssessment.assDate, 103) as 'Assessment
Date',
tblLesion.bodyRegion as 'Body Region',
tblLesion.lesLocation as 'Lesion Location',
tblSample.lesHistology as 'Histology',
tblSample.sampleNo as 'SampleNo'
FROM tblPatient, tblSample, tblAssessment, tblLesion
WHERE tblPatient.patientNo = tblSample.patientNo
AND tblPatient.patientNo = tblLesion.patientNo
AND tblPatient.patientNo = tblAssessment.patientNo
AND tblLesion.lesNo = tblSample.lesNo
AND tblPatient.pntUnitID = @patientCode
AND tblAssessment.assDate = @procedureDate
AND tblPatient.usrNo = @usrNo
GO

But the update fails, I am only wanting to update one column which
resides in the tblSample table within the database, here's the sp:

CREATE PROCEDURE proc_UpdateSampleAss
(@histology varchar(50),
@sampleNo int
)

AS

UPDATE tblSample
SET lesHistology = @histology
WHERE sampleNo = @sampleNo
GO


Below is the relevant code for Binding and updating incase it's any
use:

Binding:

SqlCommand cmd = new SqlCommand();

cmd = new SqlCommand("proc_GetSampleAss", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@usrNo", intUserNo));
cmd.Parameters.Add(new SqlParameter("@patientCode", strPatientCode));
cmd.Parameters.Add(new SqlParameter("@procedureDate",
dateProcedureDate));

sqlDataAdapter1.SelectCommand = cmd;

sqlDataAdapter1.Fill(dataSet11);
sampleDataGrid.DataBind();


Updating:

DataSet dsSampleChanges = this.dataSet11.GetChanges();
if (dsSampleChanges != null)
{
int modifiedRows = this.sqlDataAdapter1.Update(dsSampleChanges);
this.dataSet11.AcceptChanges();
messageLbl2.Text = "Data updated successfully";
}
else
{
messageLbl2.Text = "No changes to save";
}

The If statement is never executed, it always skips to the Else
statement, implying no data in the dataset has changed?

Any ideas?

Thanks

Re: Can't update dataset from datagrid by Cor

Cor
Fri Sep 02 09:09:08 CDT 2005

Assimalyst,

Probably the thousand times written in this newsgroup rowchange situation.

The data of a datagrid is pushed down to a datatable with a rowchange in
that datagrid.

You can force that with a
\\\
Bindingcontext(your datagriddatasource).endcurrentedit
///
Before where you starts your edit.


Although I find the update as well strange, however maybe I understand
something wrong.

I hope this helps,

Cor