ISYS4283 Database Wrapper
This is a simple database abstraction layer for Microsoft SQL Server.
Usage
By default, the connection string is set to use the ISYS4283 database.
' instantiate object
Dim db = New ISYS4283.DbWrapper.Db
' connect to database
db.ConnectionString = "Server=essql1.walton.uark.edu;Database=jeffpuckett;Trusted_Connection=yes;"
' execute DML
db.Sql = "INSERT INTO questions (question) VALUES (@question)"
db.Bind("@question", "What is a nuget package?")
db.Execute()
' fill a DataGridView
db.Sql = "SELECT * FROM questions"
db.Fill(DataGridView1)
' fill a ComboBox or ListBox (must have at least 2 columns selected)
' DisplayMember is set to first column
' ValueMember is set to second column
db.Sql = "SELECT username, id FROM users"
db.Fill(ComboBox1)
When using this multiple times throughout your project, you'll want to extend the class so that your code is DRY and your connection string information is only in one place.
Public Class MyDb
Inherits ISYS4283.DbWrapper.Db
Public Sub New()
ConnectionString = "Server=essql1.walton.uark.edu;Database=jeffpuckett;Trusted_Connection=yes;"
End Sub
End Class
Exception Logging
By default, a MsgBox
will simply show the error message.
To customize this, extend the Db
class and override the Log
method.
Protected Overrides Sub Log(ByRef exception As Exception)
' your custom logger implementation
End Sub
Installation
Grab the package from nuget.
In the solution explorer, right click your project references
and select Manage NuGet Packages
On the browse tab, search for ISYS4283.DbWrapper
and click the install icon on the far right for the latest version.