1
我試圖將數據保存到已從SQL Server分離並添加到解決方案資源管理器中的APP_DATA文件夾的mdf文件,但我無法做到這一點。您的幫助將不勝感激。謝謝!這裏是我的代碼:無法使用vb.net將數據保存到sql
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"/>
你有文件設置爲設計師始終複製? – APrough
你有什麼錯誤? –
如果您沒有使用它,則web.config設置是無用的。 –