VB.net
SQL Connection & Save Retrieve Date & Images Easily Using DLL Library
Hello friends,
Many among VB.net programmers know s how to connect VB.net with SQL Server Database and Save / Retrieve Records.
But here I made a DLL Library which will help you to do this job easily specially when saving images to Database or retrieving back to picturebox.
How to Use:
1. Download the dll file from here
2. Add VBSQLConnect.dll library in your project reference
3. I your project import the library
Imports VBSQLConnect.SQLConnect
4. For the database connectivity create an object of the SQLConn Class
This Class has 3 overrides
examples:
Many among VB.net programmers know s how to connect VB.net with SQL Server Database and Save / Retrieve Records.
But here I made a DLL Library which will help you to do this job easily specially when saving images to Database or retrieving back to picturebox.
How to Use:
1. Download the dll file from here
2. Add VBSQLConnect.dll library in your project reference
3. I your project import the library
Imports VBSQLConnect.SQLConnect
4. For the database connectivity create an object of the SQLConn Class
This Class has 3 overrides
examples:
Public dbconn As New
SQLConn("MYSERVER\SQLEXPRESS", "Mydb")
Public dbc As New SQLConn("Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;")
Public dbc As New SQLConn("myServerAddress","myDataBase","myUsername","myPassword")
Public dbc As New SQLConn("Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;")
Public dbc As New SQLConn("myServerAddress","myDataBase","myUsername","myPassword")
Now after the connection been made you can write the code for adding records to the Database
Steps are below.
Adding Parameters
example:
dbconn.AddParams("@name",
TextBox1.Text)
dbconn.AddParams("@photo", PictureBox1.Image)
dbconn.AddParams("@photo", PictureBox1.Image)
Executing INSERT Query
dbconn.executequery("INSERT INTO Table1 (name,photo) VALUES (@name,@photo);")
Checking for Exceptions
example:
If dbconn.hasException(True)
Then
Exit Sub
Else
MsgBox("Record Added successfully")
End If
Exit Sub
Else
MsgBox("Record Added successfully")
End If
Retrieving Records from Database
example 1:
dbconn.executequery("SELECT
* FROM Table1;")
TextBox1.Text = dbconn.dt.Rows(0).Item("name")
PictureBox1.Image = dbconn.Fetchphoto(dbconn.dt.Rows(0).Item("photo"))
TextBox1.Text = dbconn.dt.Rows(0).Item("name")
PictureBox1.Image = dbconn.Fetchphoto(dbconn.dt.Rows(0).Item("photo"))
As the records are automatically stored in a datatable names
dt, you can access directly from the datatble.
example 2:
example 2:
dbconn.executequery("SELECT *
FROM Table1;")
ComboBox1.DataSource = dbconn.dt
ComboBox1.DisplayMember = "display field"
ComboBox1.ValueMember = "value field"
ComboBox1.DataSource = dbconn.dt
ComboBox1.DisplayMember = "display field"
ComboBox1.ValueMember = "value field"
example 3.
For Each row As DataRow In
dbconn.dt.Rows
ComboBox1.Items.Add(row.Item("name"))
Next
ComboBox1.Items.Add(row.Item("name"))
Next
-------------------------------------------------------------------------------------------------------
In the Library there is also a class added for converting number or dates to words
How to Use:
Create an object of the class
Public n2w As New Num2Words
example 1:
TextBox2.Text = n2w.NumToWords(45)
Results: forty five
example 2:
TextBox2.Text = n2w.DateToText(DateTime.Now())
Results: 3rd of February two thousand eightteen
In the Library there is also a class added for converting number or dates to words
How to Use:
Create an object of the class
Public n2w As New Num2Words
example 1:
TextBox2.Text = n2w.NumToWords(45)
Results: forty five
example 2:
TextBox2.Text = n2w.DateToText(DateTime.Now())
Results: 3rd of February two thousand eightteen