嗨,我目前正在尝试在本地 .mdf 数据库中查找有关课程的详细信息,但似乎无法这样做,我已经有这个问题几个星期了,真的需要解决它,所以任何帮助都是非常感激。我将在下面的表格中包含我的代码。在此先感谢您的帮助!!
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Session As String
Session = txtSession.text
Dim con As New SqlConnection
Dim inscmd As New SqlCommand
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("RoomBookingSystem.My.MySettings.Database1ConnectionString1").ConnectionString
Try
Using cn As New SqlConnection(con.ConnectionString)
con.Open()
Dim ParamInitial As New SqlParameter
ParamInitial.ParameterName = ("@StaffInitials")
ParamInitial.Value = lblStaffInitials.Text.Trim()
inscmd.Parameters.Add(ParamInitial)
Dim ParamWeek As New SqlParameter
ParamWeek.ParameterName = ("@Week")
ParamWeek.Value = lblWeek.Text.Trim
inscmd.Parameters.Add(ParamWeek)
Dim ParamPeriod As New SqlParameter
ParamPeriod.ParameterName = ("@Period")
ParamPeriod.Value = lblPeriod.Text.Trim
inscmd.Parameters.Add(ParamPeriod)
Dim ParamDay As New SqlParameter
ParamDay.ParameterName = ("@Day")
ParamDay.Value = lblDay.Text.Trim
inscmd.Parameters.Add(ParamDay)
Dim ParamSubject As New SqlParameter
ParamSubject.ParameterName = ("@Subject")
ParamSubject.Value = lblSubject.Text.Trim
inscmd.Parameters.Add(ParamSubject)
Dim ParamYearGroup As New SqlParameter
ParamYearGroup.ParameterName = ("@YearGroup")
ParamYearGroup.Value = lblYear.Text.Trim
inscmd.Parameters.Add(ParamYearGroup)
Dim ParamNumberPupils As New SqlParameter
ParamNumberPupils.ParameterName = ("@NumberOfPupils")
ParamNumberPupils.Value = lblNoOfPupils.Text.Trim
inscmd.Parameters.Add(ParamNumberPupils)
Dim ParamControlledAssesment As New SqlParameter
ParamControlledAssesment.ParameterName = ("@ControlledAssesment")
ParamControlledAssesment.Value = lblControlledAssesment.Text.Trim
inscmd.Parameters.Add(ParamControlledAssesment)
Dim ParamRoom As New SqlParameter
ParamRoom.ParameterName = ("@Room")
ParamRoom.Value = lblRoom.Text.Trim
inscmd.Parameters.Add(ParamRoom)
Dim ParamSession As New SqlParameter
ParamSession.ParameterName = ("@Session")
ParamSession.Value = txtSession.Text.Trim
inscmd.Parameters.Add(ParamSession)
inscmd.CommandText = "INSERT INTO Booking (Week, Day, Period, Subject, YearGroup, StaffInitials, NumberOfPupils, Session, Room, ControlledAssesment)VALUES (@Week,@Day,@Period,@Subject,@YearGroup,@StaffInitials,@NumberOfPupils,@Session,@Room,@ControlledAssesment)"
'inscmd.CommandText = "INSERT INTO Booking (Week, Day, Period, Subject, YearGroup, StaffInitials, NumberOfPupils, Session, Room, ControlledAssesment)VALUES ('B','Monday',5,'Politics','U6','JAGG',5,'5','LIT','False')"
Print(inscmd.CommandText)
inscmd.Connection = con
inscmd.ExecuteNonQuery()
con.Close()
inscmd.Parameters.Clear()
End Using
' Catch ex As Exception
' MsgBox("" & ex.Message)
'if there is an error it will go here (can use Msgbox or label)
Finally
con.Close()
End Try
MsgBox("Your Booking Has Been Made Successfully")
Clicky = False
MainViewForm.btnBackToBooking.Visible = False
FormView.Show()
Me.Hide()
con.Close()
End Sub