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