我正在尝试将数据保存到已从 SQL 服务器分离并添加到解决方案资源管理器中的 APP_DATA 文件夹的 mdf 文件中,但我无法这样做。您的帮助将不胜感激。谢谢!这是我的代码:
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim EmployeeNo As Integer
Dim EmployeeName As String
Dim SupervisorName As String
Dim DateCreated As Date
Dim WeekRange As String
Dim MonthRange As String
Dim ScheduleIn As String
Dim ScheduleOut As String
Dim WorkStatus As String
EmployeeNo = EmpNoText.Text
EmployeeName = EmpNameText.Text
SupervisorName = TeamLeadDropDown.Text
DateCreated = DateCreatedTextBox.Text
WeekRange = WeekRangeTextBox.Text
MonthRange = MonthDropDown.Text
ScheduleIn = ScheduleInBox.Text
ScheduleOut = ScheduleOutBox.Text
WorkStatus = StatusDropDown.Text
Try
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\JIBKPI.mdf;Initial Catalog=JIBKPI;Integrated Security=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "INSERT INTO AgentAttendance ([EmployeeNo], [EmployeeName], [SupervisorName], [DateCreated], [WeekRange], [MonthRange], [ScheduleIn], [ScheduleOut], [WorkStatus]) VALUES (@EmployeeNo, @EmployeeName, @SupervisorName, @DateCreated, @WeekRange, @MonthRange, @ScheduleIn, @ScheduleOut, @WorkStatus,)"
cmd.ExecuteNonQuery()
MsgBox("Successfuly saved!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox("Error: Unable to save data.")
Finally
con.Close()
End Try
在我的 web.config 中,连接字符串是:
<connectionStrings>
<add name="JIBKPIConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\JIBKPI.mdf";Initial Catalog=JIBKPI;Integrated Security=True" providerName="System.Data.SqlClient"/>