Reputation: 877
I've been going through the docs for sqlite and I cannot figure out how I can return my query into an object. I can iterate through. Here is the code I've been playing with. I'm hoping someone can point me in the right direction. Thanks in advance.
Private Sub Query(ByVal SQLString As String)
Try
Dim SQLiteDRObj As SQLiteDataReader
Dim ResultsObj As DataTable = Nothing
Dim ResultSet As DataSet = Nothing
Dim SQLAdapter As SQLiteDataAdapter = Nothing
Me.GetSqlConnection()
SQLConnection.Open()
SQLCommand = New SQLiteCommand(SQLConnection)
SQLCommand.CommandText = SQLString
'SQLAdapter = New SQLiteDataAdapter("SELECT * FROM Joes2", SQLConnection)
'SQLAdapter.MissingMappingAction = MissingMappingAction.Ignore
'SQLAdapter.Fill(ResultSet, "Joes2")
SQLiteDRObj = SQLCommand.ExecuteReader()
'Put the results into an object ????
SQLiteDRObj.Close()
SQLConnection.Close()
SQLConnection.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
EDITED
Suppose I have a class such as this
Public Class Drawing
Private _ID As Guid
Private _DrawingDate As Date
Private _GameID As Guid
Public Property ID As Guid
Get
Return _ID
End Get
Set(ByVal value As Guid)
_ID = value
End Set
End Property
Public Property DrawingDate As Date
Get
Return _DrawingDate
End Get
Set(ByVal value As Date)
_DrawingDate = value
End Set
End Property
End Class
and I have a table in SQLite such as this...
Table Name is "Drawings"
ID, DrawingDate
(SomeGuid, 2014-2-14)
(SomeGUid, 2014-2-15)
and now I want to load it up like this.
Dim Drawings as New Drawing("SELECT * From Drawings")
If this is the wrong approach entirely, please let me know. I'm just trying to stick with proper OOP. (Trying to learn the right way)
Upvotes: 0
Views: 234
Reputation: 54427
This question isn't specific to SQLite. ADO.NET works basically the same no matter the provider or data source. What exactly do you mean by "into an object"? If you want to populate a DataTable with the result set then create one and call its Load method, passing the data reader as an argument. If you mean that you want to create an instance of an entity class then you would use a Do or While loop, calling Read on the data reader and getting each field value by name or ordinal.
Upvotes: 1