Stoffel85
Member
Hi,
I am trying to find the best way to interact with a database.
In school weve learned to make BaseClass and a DatabaseClass for every table in the database.
In the BaseClass comes every item from the table like this:
If I want to give some values to my DatabaseClass, I put them in the in the properties and pass them on to the DatabaseClass.
Then weve got the DatabaseClass. Here comes everything that has to do with the database (interacting). And here Im having trouble to choose.
I like to see what Im doing, so I use an SQL statement for everything I do:
In school we use Datarowviews, DataViews, DataAdapter, DataSet. Something like this:
The way I use is far more simple to work with, but is it the best way? Or is there another way thats even better than those two examples?
I am trying to find the best way to interact with a database.
In school weve learned to make BaseClass and a DatabaseClass for every table in the database.
In the BaseClass comes every item from the table like this:
Code:
...
Public Property title() As String
Get
Return mTitle
End Get
Set(ByVal Value As String)
mTitle = Value
End Set
End Property
...
Code:
...
bs.title = txtTitle.text
db.doSomething(bs)
...
Then weve got the DatabaseClass. Here comes everything that has to do with the database (interacting). And here Im having trouble to choose.
I like to see what Im doing, so I use an SQL statement for everything I do:
Code:
Public Sub doSomething(ByVal nBs As bs)
Try
Dim strSQL As String = "INSERT INTO someTable (title) VALUES(" & nBs.title & ");"
Dim cm As OleDbCommand = New OleDbCommand(strSQL, cn)
cn.Open()
cm.ExecuteNonQuery()
Catch ex As Exception
Throw New System.Exception(ex.Message)
Finally
cn.Close()
End Try
End Sub
Code:
Public Sub doSomething(ByVal nBs As bs)
Dim SortField As String = dv.Sort
Dim NewID As Integer
Try
Dim drv As DataRowView = dv.AddNew
drv("title") = nBs.title
drv.EndEdit()
da.Update(ds, "someTable")
Catch ex As Exception
ds.Tables("someTable").Clear()
da.Fill(ds, "someTable")
Throw New System.Exception(ex.Message)
End Try
End Sub
The way I use is far more simple to work with, but is it the best way? Or is there another way thats even better than those two examples?