1
我正在處理一個小型信息系統應用程序。我正在使用Windows窗體和基於服務的數據庫。這幾乎已經完成,但是當我執行應用程序時出現了一個非常奇怪的問題。我做了一個存儲過程,用於在db表格中插入數據,當我手動執行它時,它一切正常,但是當我啓動程序並通過按鈕執行過程時,發生了錯誤。乍一看程序工作正常,程序運行良好,但數據不存儲在數據庫中。這裏是我的代碼:當我啓動應用程序,數據庫下降
UserData.cs
public static bool AddStudent(Student std)
{
UserDataClassesDataContext dc = new UserDataClassesDataContext();
try
{
dc.AddNewStudent(std.FirstName, std.SecondName, std.LastName, std.Faculty, std.Specialty, std.OKS,
std.StudentStatus, std.FacNumber, std.Course, std.Potok, std.Group);
dc.SubmitChanges();
}
catch (Exception)
{
return false;
}
return true;
}
StudentValidation.cs
public bool InsertStudent(Student std)
{
return UserData.AddStudent(std);
}
MainForm.cs ButtonClick事件
private void insertStudentButton_Click(object sender, EventArgs e)
{
Student student = new Student();
student.FirstName = tbFirstName.Text;
student.SecondName = tbSecondName.Text;
student.LastName = tbLastName.Text;
student.Faculty = tbFacultyName.Text;
student.Specialty = tbSpecialty.Text;
student.FacNumber = tbFacNumber.Text;
student.OKS = (short)cbOKS.SelectedIndex;
student.StudentStatus = (short)cbStudentStatus.SelectedIndex;
student.Course = (short)numCourse.Value;
student.Potok = tbFlow.Text;
student.Group = tbGroup.Text;
if (sv.InsertStudent(student) && sv.InsertUser(student))
MessageBox.Show("The student is added successfully!");
else
MessageBox.Show("A problem occurs while trying to add the student!");
}
我認爲DB是莫名其妙地斷開時我開始申請,但我不知道爲什麼。
什麼是'UserData'? – 2013-03-08 13:08:21
聲音就像你的數據庫在開始時重新創建。你的數據庫如何部署?它是否在開始時部署? – Maarten 2013-03-08 13:08:53
你在函數'SubmitChanges()'中寫了什麼 – Pandian 2013-03-08 13:09:39