Visual Basic을 사용하여 Access 데이터베이스를 사용하는 방법을 알아 내려고 노력했지만이 사이트에서 참조한 모든 라이브러리 (ADODB 등) 인터넷은 VS2013에 존재하지 않거나 Recordset 개체 (OleDb는 그러한 라이브러리 중 하나)와 같은 모든 기능을 사용하지 않습니다. 이것은 '올바른 라이브러리를 설치해야합니까?'의 경우입니까? 아니면 Microsoft 데이터베이스로 작업하면서 새로운 표준을 놓치고 있습니까?Visual Studio 2013에서 Access 데이터베이스 작업
0
A
답변
1
그것은 잘못된 클래스를 사용하여, 사실, 내가이었다 밝혀졌습니다. here (Thanks @Plutonix)은 DataSet11 및 OleDbAdapter1 개체에 대한 참조를 만듭니다.이 개체를 함께 사용하면 이전 DAO 및 ADO Recordset 개체에서 본 일종의 기능이있는 것처럼 보입니다.
0
간단한 Microsoft Access 2000 데이터베이스 백엔드 인 VB.NET을 사용하는 ASP.NET 웹 사이트가 있습니다. 실제로 데이터베이스에서 특정 테이블과 쿼리 및 데이터를 가져 오기 위해 자체 사용자 지정 클래스를 작성했으며 OleDb를 기반으로합니다. 사용할 수있는 최고의 코드는 아니며 사실 조금 부끄럽습니다. 하지만 그것을 사용하는 간단한 응용 프로그램에 대한 작업이 완료됩니다. 파일 AccessData.vb의 파일 AccessDatabase.vb의
컷 버전
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Public Class AccessDatabase
Friend db As New OleDbConnection
Private sPath As String
Public Sub New(ByRef sPath As String)
GetDatabase(sPath)
End Sub
'Use Server.MapPath("App_Data\WebContent.mdb") to load the database.
Private Function GetDatabase(ByRef sPath As String) As OleDbConnection
Try
If db.State <> System.Data.ConnectionState.Open Then
db = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath)
db.Open()
End If
Catch e As Exception
Throw New Exception("Exception encountered when attempting to open database " & sPath, e)
End Try
Return db
End Function
Public Function GetTable(ByRef sTableName As String, Optional ByRef sWhere As String = "", Optional ByRef sSort As String = "") As AccessData
Dim a As New AccessData(Me)
a.SetTable(sTableName, sWhere, sSort)
Return a
End Function
Public Sub Close()
If db.State <> Data.ConnectionState.Closed Then
db.Close()
End If
End Sub
Protected Overrides Sub Finalize()
Try
If Not db Is Nothing Then
If db.State <> Data.ConnectionState.Closed Then
db.Close()
End If
End If
Catch ex As Exception
End Try
End Sub
End Class
컷 버전은
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Public Class AccessData
Private db As AccessDatabase
Private data As OleDbDataReader
Public Sub New(ByRef d As AccessDatabase)
SetDB(d)
End Sub
Public Sub New(ByRef d As AccessDatabase, ByRef sTableName As String, Optional ByRef sWhere As String = "", Optional ByRef sSort As String = "")
SetDB(d)
SetTable(sTableName, sWhere, sSort)
End Sub
Public Sub SetDB(ByRef d As AccessDatabase)
db = d
End Sub
Public Sub SetTable(ByRef sTableName As String, Optional ByRef sWhere As String = "", Optional ByRef sSort As String = "")
If sWhere = "" And sSort = "" Then
SetFromQuery("SELECT " & sTableName & ".* FROM " & sTableName)
ElseIf sSort = "" Then
SetFromQuery("SELECT " & sTableName & ".* FROM " & sTableName & " WHERE " & sWhere)
ElseIf sWhere = "" Then
SetFromQuery("SELECT " & sTableName & ".* FROM " & sTableName & " ORDER BY " & sSort)
Else
SetFromQuery("SELECT " & sTableName & ".* FROM " & sTableName & " WHERE " & sWhere & " ORDER BY " & sSort)
End If
End Sub
Public Sub SetFromQuery(ByRef sQuery As String)
Dim c As OleDbCommand
c = New OleDbCommand(sQuery, db.db)
data = c.ExecuteReader()
End Sub
'Returns the value of the requested field of the current row of the reader
Public Function GetValue(ByRef sField As String) As String
Dim iOrdinal As Integer
Try
iOrdinal = data.GetOrdinal(sField)
If Not data.GetValue(iOrdinal).Equals(DBNull.Value) Then
Return data.GetValue(iOrdinal).ToString()
End If
Catch e As System.IndexOutOfRangeException
Throw New System.IndexOutOfRangeException("Field '" & sField & "' was requested from " & vbCrLf & sQuery & "," & vbCrLf & "but it does not exist.", e)
Catch e As System.InvalidOperationException
Throw New System.InvalidOperationException("No data exists for the current row in field '" & sField & "'. Make sure you have performed a Read() operation and that you are not at the EOF or BOF of the data stream.", e)
End Try
Return ""
End Function
'This will close the stream when data.Read() returns false
Public Function Read() As Boolean
Dim bResult As Boolean
bResult = data.Read()
If Not bResult Then
data.Close()
End If
Return bResult
End Function
End Class
관련 문제
- 1. Visual Studio 2013에서 테스트가 사라졌습니다.
- 2. C# visual studio 2015 Access 2013 데이터베이스
- 3. MS Access (C#)로 Visual Studio 2013에서 송장 생성
- 4. Visual Studio 2013에서 QT 사용
- 5. Visual Studio 2013에서 nuget.config가 무시됩니다.
- 6. Visual Studio 2013에서 Javascript 디버그
- 7. 문제 Visual Studio 2013에서 .edmx EF6 생성
- 8. Visual Studio 2013에서 제한된 WCF 호출보기
- 9. Visual Studio 2013에서 데이터 연결이 끊어졌습니다.
- 10. Microsoft는 Visual Studio 2013에서 데이터베이스 다이어그램을 제거 했습니까?
- 11. Visual Studio 2013에서 웹 API 프로젝트 실행
- 12. Visual Studio 데이터베이스 프로젝트에서 실행 작업 변경
- 13. Visual Studio 2013에서 잘못된 구성 파일을 사용합니다.
- 14. Access 데이터베이스 작업
- 15. Visual Studio 2013에서 "기본값"코드 생성 전략
- 16. Visual Studio 2013에서 Godaddy.com으로 배포하는 방법
- 17. Script #가 Visual Studio 2013에서 작동합니까?
- 18. Visual Studio 2013에서 디자인보기가 작동하지 않습니다.
- 19. Visual Studio 2013에서 .pdb 파일을 제거 하시겠습니까?
- 20. Visual Studio 2013에서 C++이 정의되지 않았습니다.
- 21. Visual Studio 2013에서 libpq 사용, DLL로 컴파일
- 22. Visual Studio 2013에서 RestSharp를 호출하는 방법은 무엇입니까?
- 23. Visual Studio 2013에서 테이블을 추가하는 방법은 무엇입니까?
- 24. Visual Studio 2013에서 Microsoft Git Provider를 중지하십시오.
- 25. Visual Studio 2013에서 LNK 1168 오류를 제공합니다
- 26. Visual Studio 2013에서 TypeScript 컴파일 타겟
- 27. Visual Studio 2013에서 디자인보기를 표시하지 않습니다.
- 28. Visual Studio 2013에서 체스 조각을 인쇄하려고합니다.
- 29. Visual Studio 2013에서 자동으로 .csproj를 체크 아웃
- 30. 키 바인딩 Visual Studio 2013에서 탭 전환
http://support.microsoft.com/kb/821765 – Plutonix
http://social.msdn.microsoft.com/Forums/vstudio/en-US/5e917e8f-6d39-4226-8940-bf9560f78d1d/vs-2013 -connection-to-access-database? forum = vbgeneral @Plutonix가 제안한 것과 함께. 두 링크 모두 당신을 당신의 답으로 인도합니다. –