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"/>