D
Dephic
Unregistered / Unconfirmed
GUEST, unregistred user!
刚才打了一半天,竟出错,又重打了一轮,倒。。。。
具体情况:
机器的软件环境:win2000服务器版+SQLSERVER2000企业版
底层MTS数据模块(TMtsDataModule):TADOConnection + TADODataSet +TDataSetProvider
TDataSetProvider.ResolveToDataSet:= true
TDataSetProvider.OPtions := [poAllowCommandText]
接口过程:
//Delta为从MTS协调层(MTSOBJECT)的ClientDataSet传下来的更新数据封包
//SQLSTR为在 ClientDataSet上执行的SQL语句,执行的是的存储过程
procedure TCreditManageDM.UpdateCreditManage(Delta: OleVariant;
MaxError: Integer;
const SqlStr: WideString;
var ErrorCount: Integer);
begin
adodsCreditManage.CommandText := SqlStr;
dspCreditManage.ApplyUpdates(Delta,MaxError,ErrorCount);
end;
//BeforeUpdateRecord处理事件
procedure TCreditManageDM.dspCreditManageBeforeUpdateRecord(
Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
begin
//删除三个字段的可更新数据标记,以防止其更新入数据库
if (pfInUpdate in DeltaDS.FieldByName('SpecialtyName').ProviderFlags) then
DeltaDS.FieldByName('SpecialtyName').ProviderFlags :=
DeltaDS.FieldByName('SpecialtyName').ProviderFlags - [pfInUpdate];
if (pfInUpdate in DeltaDS.FieldByName('SubjectTypeName').ProviderFlags) then
DeltaDS.FieldByName('SubjectTypeName').ProviderFlags :=
DeltaDS.FieldByName('SubjectTypeName').ProviderFlags - [pfInUpdate];
if (pfInUpdate in DeltaDS.FieldByName('TeacherName').ProviderFlags) then
DeltaDS.FieldByName('TeacherName').ProviderFlags :=
DeltaDS.FieldByName('TeacherName').ProviderFlags - [pfInUpdate];
end;
ClientDataset执行的存储过程:
--WDQ
CREATE PROCEDURE GetTermLesson --学期开课表
@GradeInSchool varchar(20), --年级
@SpecialtyNo varchar(5), --专业代码
@SubjectNo varchar(20), --科目代码
@SubjectName varchar(30), --课程名称
@SubjectTypeNo varchar(5), --课程类型 必修,选修等。。
@TeacherNo varchar(20), --教师代码
@TeacherName varchar(20), --教师姓名
@IsOpen1 Bit, --是否开课 0-不开课
@IsOpen2 Bit, --是否开课 1-开课
@Term varchar(9), --学期
@GradeMode1 bit, --评分方法 0-等级评分 1-成绩评分
@GradeMode2 bit --评分方法 0-等级评分 1-成绩评分
AS
begin
SELECT A.ID ,
A.GradeInSchool,
A.SpecialtyNo,
B.Name AS SpecialtyName,
A.SubjectNo,
A.SubjectName,
A.SubjectTypeNo,
D.Name AS SubjectTypeName,
A.TeacherNo,
C.Name AS TeacherName,
A.IsOpen,
A.Term,
A.Credit,
A.Factor,
A.PassScore,
A.MaxNum,
A.MinNum,
A.GradeMode
FROM
TermLesson AS A
LEFT JOIN SpecialtyInfo AS B ON A.SpecialtyNo = B.SpecialtyNo
LEFT JOIN TeacherInfo AS C ON A.TeacherNo = C.TeacherNo
LEFT JOIN SubjectType AS D ON A.SubjectTypeNo = D.SubjectTypeNo
WHERE
A.GradeInSchool LIKE @GradeInSchool AND --年级
A.SpecialtyNo LIKE @SpecialtyNo AND --专业代码
A.SubjectNo LIKE @SubjectNo AND --科目代码
A.SubjectName LIKE @SubjectName AND --课程名称
A.SubjectTypeNo LIKE @SubjectTypeNo AND --课程类型
A.TeacherNo LIKE @TeacherNo AND --教师代码
-- C.Name LIKE @TeacherName AND --教师姓名
(A.IsOpen = @IsOpen1 OR
A.IsOpen = @IsOpen2) AND --是否开课
A.Term LIKE @Term AND --学期
(A.GradeMode = @GradeMode1 OR
A.GradeMode = @GradeMode2)
END
GO
问题:
(各表已经设好主建,如果不设主键会出现错误)
在ClientDataSet端进行添加,修改操作时更新回数据库正常,不会影响到JOIN进来的几个数据字典表
但在执行删除操作时却把JOIN进来的几个表的对应记录全删了!怎么解决?这个问题我已经折腾了一天了!
哪位大虾能帮帮我?谢谢了!
具体情况:
机器的软件环境:win2000服务器版+SQLSERVER2000企业版
底层MTS数据模块(TMtsDataModule):TADOConnection + TADODataSet +TDataSetProvider
TDataSetProvider.ResolveToDataSet:= true
TDataSetProvider.OPtions := [poAllowCommandText]
接口过程:
//Delta为从MTS协调层(MTSOBJECT)的ClientDataSet传下来的更新数据封包
//SQLSTR为在 ClientDataSet上执行的SQL语句,执行的是的存储过程
procedure TCreditManageDM.UpdateCreditManage(Delta: OleVariant;
MaxError: Integer;
const SqlStr: WideString;
var ErrorCount: Integer);
begin
adodsCreditManage.CommandText := SqlStr;
dspCreditManage.ApplyUpdates(Delta,MaxError,ErrorCount);
end;
//BeforeUpdateRecord处理事件
procedure TCreditManageDM.dspCreditManageBeforeUpdateRecord(
Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
begin
//删除三个字段的可更新数据标记,以防止其更新入数据库
if (pfInUpdate in DeltaDS.FieldByName('SpecialtyName').ProviderFlags) then
DeltaDS.FieldByName('SpecialtyName').ProviderFlags :=
DeltaDS.FieldByName('SpecialtyName').ProviderFlags - [pfInUpdate];
if (pfInUpdate in DeltaDS.FieldByName('SubjectTypeName').ProviderFlags) then
DeltaDS.FieldByName('SubjectTypeName').ProviderFlags :=
DeltaDS.FieldByName('SubjectTypeName').ProviderFlags - [pfInUpdate];
if (pfInUpdate in DeltaDS.FieldByName('TeacherName').ProviderFlags) then
DeltaDS.FieldByName('TeacherName').ProviderFlags :=
DeltaDS.FieldByName('TeacherName').ProviderFlags - [pfInUpdate];
end;
ClientDataset执行的存储过程:
--WDQ
CREATE PROCEDURE GetTermLesson --学期开课表
@GradeInSchool varchar(20), --年级
@SpecialtyNo varchar(5), --专业代码
@SubjectNo varchar(20), --科目代码
@SubjectName varchar(30), --课程名称
@SubjectTypeNo varchar(5), --课程类型 必修,选修等。。
@TeacherNo varchar(20), --教师代码
@TeacherName varchar(20), --教师姓名
@IsOpen1 Bit, --是否开课 0-不开课
@IsOpen2 Bit, --是否开课 1-开课
@Term varchar(9), --学期
@GradeMode1 bit, --评分方法 0-等级评分 1-成绩评分
@GradeMode2 bit --评分方法 0-等级评分 1-成绩评分
AS
begin
SELECT A.ID ,
A.GradeInSchool,
A.SpecialtyNo,
B.Name AS SpecialtyName,
A.SubjectNo,
A.SubjectName,
A.SubjectTypeNo,
D.Name AS SubjectTypeName,
A.TeacherNo,
C.Name AS TeacherName,
A.IsOpen,
A.Term,
A.Credit,
A.Factor,
A.PassScore,
A.MaxNum,
A.MinNum,
A.GradeMode
FROM
TermLesson AS A
LEFT JOIN SpecialtyInfo AS B ON A.SpecialtyNo = B.SpecialtyNo
LEFT JOIN TeacherInfo AS C ON A.TeacherNo = C.TeacherNo
LEFT JOIN SubjectType AS D ON A.SubjectTypeNo = D.SubjectTypeNo
WHERE
A.GradeInSchool LIKE @GradeInSchool AND --年级
A.SpecialtyNo LIKE @SpecialtyNo AND --专业代码
A.SubjectNo LIKE @SubjectNo AND --科目代码
A.SubjectName LIKE @SubjectName AND --课程名称
A.SubjectTypeNo LIKE @SubjectTypeNo AND --课程类型
A.TeacherNo LIKE @TeacherNo AND --教师代码
-- C.Name LIKE @TeacherName AND --教师姓名
(A.IsOpen = @IsOpen1 OR
A.IsOpen = @IsOpen2) AND --是否开课
A.Term LIKE @Term AND --学期
(A.GradeMode = @GradeMode1 OR
A.GradeMode = @GradeMode2)
END
GO
问题:
(各表已经设好主建,如果不设主键会出现错误)
在ClientDataSet端进行添加,修改操作时更新回数据库正常,不会影响到JOIN进来的几个数据字典表
但在执行删除操作时却把JOIN进来的几个表的对应记录全删了!怎么解决?这个问题我已经折腾了一天了!
哪位大虾能帮帮我?谢谢了!