我有一個數據庫,一個簡單的存儲過程被稱爲AddNewStudent:存儲過程不插入到表
CREATE PROCEDURE dbo.AddNewStudent(
@fName nvarchar(20),
@sName nvarchar(20),
@lName nvarchar(20),
@faculty nvarchar(10),
@specialty nvarchar(50),
@OKS smallint,
@StudentStat smallint,
@fak nvarchar(50),
@Course smallint,
@Porok nvarchar(5),
@Group int
)
AS
INSERT INTO [Students] (FirstName, SecondName, LastName, Faculty,
Specialty, OKS, StudentStatus, FakNumber, Course, Potok, [[Group]]])
VALUES (@fName , @sName, @lName, @faculty, @specialty, @OKS,
@StudentStat, @fak, @Course, @Porok, @Group)
RETURN 2;
當我通過DatabaseExplorer測試程序(VS2013)一切正常,並記錄插入進入桌子。但是當我在c#中調用過程時,什麼都不會發生。貝婁是我用來調用的程序方法的代碼:
public static bool InsertStudent (Student student)
{
StudentDataClassesDataContext dc = new StudentDataClassesDataContext();
try
{
int returnValue = dc.AddNewStudent(student.FirstName, student.SecondName, student.LastName, student.Faculty, student.Specialty, student.OKS, student.StudentStatus,
student.FakNumber, student.Course, student.Potok, student._Group_);
dc.SubmitChanges();
MessageBox.Show("Return Value : " + returnValue, "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception e)
{
MessageBox.Show("Exception : " + e.Message, "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
返回的值是2,這意味着程序做它的工作,但爲什麼沒有插入到表中的記錄?我讀了使用dc.SubmitChanges()而不是Commit。
您是否看到帶有「返回值:2」的消息框? –
你正在使用什麼**連接字符串**? –
您是否在您的存儲過程結束時提交? – Ramie