VB.NET Tutorial – Connect & Query a Microsoft SQL Server Database – Part 1

In this VB.NET Database Tutorial, I will show you how to connect and query a Microsoft SQL Server database from your Visual Basic .NET application. We will build an improved connection control class for simplified access to our database.

Additionally, we will create a database search feature with wildcard support and populate a DataGridView and ComboBox with a database query.

0:25 Preparing the database
15:34 Creating your application
26:35 Building your SQL Control Class
1:06:00 Using the SQL Control Class
1:09:10 Query SQL to a DataGridView
1:16:33 Building a parameterized search with wildcard support
1:24:04 Populate a ComboBox with SQL Query results
1:30:30 Error Testing


Thank you for your support!


Ken Clemer Baltar says:

nice a new video 🙂

Gr8pe says:

Thanks for these videos!! I’ve been using them for my job and they’ve helped me tons!! you’re the best!

Ghulam Habib says:

Thank you for nice tutorial.

Kris Cam says:

I just discovered your channel and Holy adsadjaskdsajd you are saving my life now. I wonder why you don’t get million of views! Thank you so much bro

Sali Makdum says:

Hi, im getting this errror Login Failed for User ‘tutorial’… can you help me with this error.. thank you

Cylon39 says:

Your BACK!!! Wonderful videos!!!
Thanks for posting them… So helpful.

Pramod Negi says:

Thanks for sharing knowledgeable video. You are an Erudite Person. Can you please help in to use the program to get multiple return parameters.

Dev Williams says:

Excellent material and presentation. Helping me quite a bit. Quick question: Do you have a video showing how to convert the ExecQuery sub into an ExecSP (stored procedure) sub? I have toyed with it a bit, seems that the trick is to change the command object and to handle the parameters. i seem to be deficient with regard to the latter.

Matt McAllister says:

Hi, thanks very much for sharing your work! It’s incredibly helpful. Do you if you could use your SQLControl class for an ODBC connection?

Bound Hell says:

dude i love you so much right now, you just saved me from the fucking assignment. thank godness i find you here

Matt McAllister says:

awesome tutorial! thanks so much

Niket Agarwal says:

What can I do here to use this code as a transaction? I am facing problems in implementing rollback and commit.

niloy das says:

Hi, i need to store an integer value from one of the cells to a variable. I need to use Execute Scalar but i cant understand how to call that using the SQLControl class. Can someone help please?

SER NGUANG Toh says:

So good your video… thank you so much…

Need your help …

What should be following code like  if there is more than 1 search field, eg search by firstName (Like) and lastName  (Like) and age eg between 20 and 30 … all at the same time.


Private Sub FindItem()
        SQL.AddParam(“@item”, “%” & txtSearch.Text & “%”)
        LoadGrid(“SELECT PartNo,PartDesc FROM Products WHERE PartNo LIKE @item;”)
End Sub

nickos chainis says:

Hi VBToolbox. i have a problem with the login. I connect the sql db with windows authentication, everything looks good , but when the code run and try to DBCon.Open() takes a fault “Login Failed foe user….” any suggestion?

Julius Albano says:

Hi .. I.m facing problem in executing query in my DataGrid.. Error Mesage “Object reference not set to an instance of an object” …. I tried to replace the table name from my own SQL table against your sample but it seems not identified….Can you provide any help how I can connect to my data table. Thanks


How come you don’t have many views? your video is all i needed; Thanks man,. I dont know how to thank you, i have struggled alot to create. One bit you need to explain is how to use the Combo box to narrow the results in the grid


Hi VBToolBox ,when i use this code—— Params.ForEach(Sub(p) DBCmd.Parameters.Add(p)) and Params.Add(NewParam)
but ForEach give error i used vb.net 2012 Plz solve the problem thanks

Niket Agarwal says:

Hey! I am facing a problem when I try to connect to my server using an IP address. Error pops up saying- “The server was not found or was not accessible”. Is there anything wrong in the connection string?

VaderFaderVader says:

Awsome!! I’ve litteraly just finished Part5, and was a little sad to miss the “User Manager” -part. And then the Updated version you mentioned 10 months ago, suddenly pops up.
Thanks – your tutorials are really useful & informative. I’m learning a lot from you!.

OfficalAtrix | Quit says:

Nice… SSMS generates a random password if i choose SQL-Authentication, any help?

Justin Laird says:

At 42:00 you give us the option to change the connection string, but I don’t see any examples of how to actually do it. I am using other parts of your code and it’s been flawless so far, but I’m at a point where I need to connect to a different SQL server. Can you provide any direction on how to do this?

Mirko Markovic says:

So clean and nice code! This was very helpful, thanks a lot.

Steven Carter says:

can i get the code used in this tutorial?

TheJawtech says:

GREAT tutorial, dude you have saved my application. I haven’t done much newer VB but was pretty awesome with VB6. I’ve got my application together but for the life of me cannot get the “built in” stuff to work with the logic I need. I had realized that the default controls were not going to be much help but it’s not like you see their code so there is nothing to change. Tableadapters seem to be a nightmare. This sqlcontroller class is EXACTLY what I was missing.

Robert Terlaak says:

Very nice stuff, just what I was looking for. I need to convert a semi large project in Visual Fox Pro to something new(er). This combination of Visual Studio and SQL server should be a way to make everything look and feel the same for the users.

Clash of Clans says:

awesome and really helpful code for learners.

Khalid Afridi says:

Thanks a lot, It’s really awesome 🙂 so clean and simple.

Hannu Lappalainen says:

Don´t know why Search does not work me.

Private Sub finditem()
SQL.Addparam(“@item”, “%” & TextBox1.Text & “%”)
loadGrid(“Select * from asukkaat where Nimi LIKE @item;”)
End Sub

Private Sub Inventory_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MdiParent = Form1

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub

 Write a comment


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!