This is a simple database abstraction layer for Microsoft SQL Server.
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.
Extend the class and set your connection string in the constructor.
Public Class Db
Inherits ISYS4283.DbWrapper.Db
Public Sub New()
ConnectionString = "Server=essql1.walton.uark.edu;Database=insert_database_name_here;Trusted_Connection=yes;"
End Sub
End Class
class Db : ISYS4283.DbWrapper.Db
{
public Db()
{
ConnectionString = "Server=essql1.walton.uark.edu;Database=insert_database_name_here;Trusted_Connection=yes;";
}
}
Here's some examples filling form controls from a database in VB.
' instantiate object
Dim db = New Db
' 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)
Similarly in c#
Db db = new Db();
db.Sql = "SELECT * FROM users WHERE id = @id";
int id = 1;
db.Bind("@id", id);
db.Fill(ref dataGridView1);
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
Pull requests are welcome.
Here are some notes on building the nuget packages.
Create alias:
doskey pack=nuget pack ISYS4283.DbWrapper.vbproj
Create nuget package:
pack
Add local directory as package source in visual studio.
Test accordingly.
Add API key for publishing a release:
nuget setApiKey Your-API-Key
Push release:
nuget push YourPackage.nupkg -Source https://api.nuget.org/v3/index.json