if you are using ExecuteNonQuery(), check its return value int nRowAffected = YourCommand.ExecuteNonQuery(); if (nRowAffected > 0) { //成功 }if you are using DataAdapter, you could get expected if the 更新 failed and check each Row's RowError property
如果你用存储过程可以这样写: CREATE procedure InsertLesson ( @LessonName nvarchar(40), @LessonTime smallint, @WhichDepartmentLearn nvarchar(40), @IsCompel smallint ) AS IF EXISTS(……) SELECT 2 ELSE
BEGIN INSERT INTO Lesson (LessonName, LessonTime, WhichDepartmentLearn, IsCompel) VALUES(@LessonName, @LessonTime, @WhichDepartmentLearn, @IsCompel) SELECT 1 END GO 调用存储过程,如下 int iStatusCode = Convert.ToInt32(myCommand.ExecuteScalar()); 这样如果等于1就表示成功插入了。
int nRowAffected = YourCommand.ExecuteNonQuery();
if (nRowAffected > 0)
{
//成功
}if you are using DataAdapter, you could get expected if the 更新 failed and check each Row's RowError property
CREATE procedure InsertLesson
(
@LessonName nvarchar(40),
@LessonTime smallint,
@WhichDepartmentLearn nvarchar(40),
@IsCompel smallint
)
AS
IF EXISTS(……)
SELECT 2
ELSE
BEGIN
INSERT INTO Lesson (LessonName, LessonTime, WhichDepartmentLearn, IsCompel)
VALUES(@LessonName, @LessonTime, @WhichDepartmentLearn, @IsCompel)
SELECT 1
END
GO
调用存储过程,如下
int iStatusCode = Convert.ToInt32(myCommand.ExecuteScalar());
这样如果等于1就表示成功插入了。
TRY
{
数据库操作
....
在此加入弹提示框代码
}
catch(Exception ex)
finish()