VB.NET Tutorial - Connect & Query a Microsoft SQL Server Database - Part 1
Вставка
- Опубліковано 16 лип 2024
- 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.
SHORTCUTS:
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
PROJECT SOURCE CODE:
www.dropbox.com/s/80025odtkct...
Thank you for your support!
Thank you very much for a well-organized, clear tutorial. I did a lot of VB4 programming in the 1990s but none since. I retired a few years ago and wanted to resurrect and continue a project I did back then. This video served as a great refresher and I am ready to continue your series.
Thank you very much for this. It's very useful and I like your laconic style :-) I'm using VS2019.
I'm 72 years old, retired, and I'm having fun exercising my mind learning VB.net and Visual Studio. I've been programming off and on since the late 1960s. The off periods were when I was managing mainframe software projects, doing strategic planning and being an IT Director for an insurance company. Programming is more fun. I started with FORTRAN at uni, then went onto Assembler, machine code, COBOL, ALGOL with Burroughs, used Burroughs DMSII, IBM's IMS, Digital's Rdb until I retired from the corporate rat race, bought a copy of Access when it was first released and had to learn VBA. I learned enough VB6 to modify existing systems. I got into SQL Server in 1997 and became an accidental DBA. I had such a lucrative business developing systems with Access front ends to SQL Server that I never got around to learning .net. I became fluent in T-SQL. I've flirted with learning VB.net a few times, but commercial pressured got in the way. I subscribed to an online learning company and didn't get much satisfaction. This tutorial of yours is exactly what I've been looking for to learn VB.net and how to interface with SQL Server. You explain things at the level I need. Thank you very much.
Thank you so much! These DB tutorial videos are super - I've learned a lot. Your content is well laid out and your presentation is excellent.
Hi, many thanks for this VB tutorial, by far is the best from what i found on UA-cam so far and i was looking for a while (few months).
Hi VBToolbox. Glad to see you active again. I hate moving too--I think most people do. At 66 years old I have done it 20 times so far in my adult life. I followed many of your DB tutorials in the past, and am waiting to see what you will present next. When you fill the combo box you can use a row index like r(0) instead of the column name. No big deal. It's just shorter.
I've found this video equal parts challenging and rewarding. Rewarding because it has expanded my knowledge about databases and how sql works. Challenging because there are aspects of the coding that are above my self-taught level. To that extent if there is anyone who would be kind enough to show me how to make use of the Over-ride code in very very simple terms I would be extremely grateful. Thank you.
UPDATE: I have done some thinking and reading and I re-watched this video and realise that the answer to my question was there all along - I just didn't understand enough to fully recognise it. Thanks for this video - it's been a great catalyst for learning so much new material for someone who started learning Vb by hacking excel macros.
Many thanks.
Same Here
My good sir, you are a lifesaver. I should browse through your channel. i have a feeling you will become one of my best teachers!
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.
JAW
never seen like the way you teach before, thanks a million....
wish you could post more of tutorial videos.....
Thanks for these videos!! I've been using them for my job and they've helped me tons!! you're the best!
Awesome! I'm very happy that they're helping you out. I'm envious that you get to do this for work. :-D
Just started this SQL series of videos after your Access ones. Excellent and a lot to learn😊
Awesome! Very happy you're enjoying the series! SQL server is still my favorite DB to work with. :-)
THank you I'm newbie and I really appreciated your work here
Thanks for such a sweet explanation - really loved this tutorial and started following your series
Thank you so much .................................!!
You're doing a great help to the generations of learners
Thanks man, your videos made transitioning from VB6 to .net easy!
This is great. Have been searching for time to find the right stuff where it is explained well. This did. Thanks just did part one have to go for the other parts.
It feels as you sitting beside us and showing.
Tanks a lot.
I'm very happy that the tutorials have been helpful! :-)
Your tutorials are too good to exist. 10000/10
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!.
Hah! Suhweet! :-) I really hope I can deliver this time around. Been trying hard to get caught up after my move.
can you help me with that error? and by the way thanks for the reply i really appreciate it. also thanks for uploading this video tutorial it really helps a lot
Very nice tutorial !!! waiting for the next video, hope comes soon. Thanks a lot.
Your BACK!!! Wonderful videos!!!
Thanks for posting them... So helpful.
I hope so! Figured I'd best get to it whilst there's a lull in the chaos. :-D
You just saved my life :) Thank you!
Thanks I could simplify my code at work a lot using this SQL control class.
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
Awesome! Always happy to save a life! ;-D
Thank you so much for this great tutorial. its as always very helpful and easy to degust thanks to your easy way of explaining things.
Thanks for the tutorials. Great Examples for real work and great for teaching
Great detailed intro to using VB.NET with SQL Server... Thanks... Mike in LA, Calif, USA. Believe it or not I have made tons of money using MS Access/VBA as a front-end to SQL Server on a LAN because it's much quicker to build with and has a great report writer built-in. But at some point you will outgrow MS Access as a front-end(you can still use it for other smaller apps), and need more speed and more options as a front-end and that means going to C# or VB .Net Winforms(or WebForms - ASP.NET) to re-create that front-end. And that's me now... LOL... Thanks again for the info.
UNICOMP Awesome! Now, if I could just get you to make me a tutorial on how to make tons of money (or even a little money) with Access and/or VB, that would be ultra rad! 😋
Thank you for the great comment!
dude i love you so much right now, you just saved me from the fucking assignment. thank godness i find you here
Thanks a lot, It's really awesome :) so clean and simple.
Thanks for this Simple and reach tutorial.
LOVE it - You are a life saver.
Your tutorial was very helpful for me. Thanks A lot.
OOOH BUSTED, you gave it away! I saw that WoW folder, lol. Tell me you're not a night elf hunter named legolas :P
🤣 That was a looong time ago - but I was a gnome DK, back in the day.
Thanks for the tutorial! I really like the clean codes using classes, still learning for this skill :)
This is an excellent video series - written for VB2010 but I'm following easily in VB2017 SQL server 2017
wow that was an amazing tutorial, really clear code and well explained
So clean and nice code! This was very helpful, thanks a lot.
Thank you this series will help me with my project
You little marvel! You've gone and made functions into programs!!
🤣 You're killin' me, Anthony!
Welcome back bro. Thumbs up for your efforts!!
22:24 - THIS IS the BEST THING I'VE HEARD!!! EXACTLY what I'm trying to do... THANK YOU!!!
Really great!, we expect such more other videos, Thanks a lot.
Great Video, Thank you so much
Perfectly explained!!!
Nice and smooth tutorial, thanks a lot.
Never give up
Amazing Tutorial Man!
awesome tutorial! thanks so much
Great Resource, Thank You Sir you're the best
You are absolutely amazing. :)
Great tutorial! Thank you!
thank you so much , that was really good ,, thanks million times
Interesting. I'll check out sometimes. Thanks.
Thank you for nice tutorial.
Great work. Thanks for this great job.
wow, awsome, thanks for this, tomorrow I will start with part 2
Great tutorial!! Best I have seen!
Hi VBT
Ill start by saying that this tutorial is absolutley fantastic!! - i was looking forever for a good video that explains this well so i'm really pleased you've taken the time to upload your knowledge to UA-cam for us all :)
My Question is, willt his SQL Control Class work ok with a multi-user application accessing a single Database? or will conflicts still happen?
Many thanks!
Well done!
You are a legend...
The tutorial is excellent
Thanks bro
Thx lot Bro . Very helpful tutorial . God bless you
Great Video/ Learned a bunch
awesome and really helpful code for learners.
Brilliant Videos for us newbies!!
Building my first Program following as much of your work as I can, but have a real problem!!!
I have copied Private Sub LoadCBX and renamed it, now I want to call up DataBase Column names only, so I can try and work out how to search with certain columns.
Hope you can help
BIG thank you !!!
Are you thinking of something like a dynamic query - or populating a ComboBox with table or column names? I did a video on this for MS Access, but SQL Server is slightly different - a little easier actually.
In a nutshell, your query will look something like this:
[In your ExecQuery]
SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'yourTable'
After that, you populate your CBX from your DataTable [SQL.DBDT] just like you normally would with any other query.
I hope that helps! :-)
Really sorry for late reply as you replied straightway to me!, but I was like a child with new tool, got all excited and went off and watched your Access tutorial, and that was exactly what i was after.
Thank you so so much!!!!
Your brilliant
Excellent Teaching
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?
Thanks!
Amazing thanks alot
love you bro!
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.
Awesome! I've had to do a bit of work in a SQL/VFP hybrid environment. Not gonna lie, I was tremendously happy to see VFP go the way of the dodo. :-P I had a VFP connector class [like my SQLControl] that would make it pretty easy to migrate data from VFP to SQL, but I recently moved and I'm not sure where that class went. :-(
Awesome 👍
YOU ARE THE VB GOD
Cooooool !!!! Thanks )))
Thank you!!!!!!!!!!!!!
you are the best thank u
Love your tutorials. Do you have any with transaccions, love to learni more on this matter.
nice a new video :)
Yes, indeed. Sorry that it has to be the same old topics, but it was long overdo and I still get a ton of questions on the old video so I really wanted to refresh them.
always looking into your new uploads bro keep it up
Thanks man!! That's a wonderful video! I'll see every single one now! I'm initiating on Vb.NET now, after various developments in Excel VBA, and that helped me a LOT!
Hope there's much more yet!
Congratulations!
Very clear, simple and easy to undestand for us beginners. Used your override sub from the DBcontrol class, ( new(connectionString) and getting a type exeception.
How to fix ?
Thanks
Hello I haven't visit your videos in a while. I been away But again very nice video keep up the great work.
Always great to see you, Joseph! I apologize for my slow responses. I'm still getting settled from my move and it's been difficult to keep up with all of the comments and questions and even more difficult to make new content. I'm trying to get caught up, though. :-)
I didn't know you moved. I'm soon to move my self.
Yep, and I'll be moving again in less than a year, so it's going to be hard to keep up but I'll do what I can. I hate moving, but we gotta chase those goals and dreams, right?
Just a update how did the move go? I know it has been a while so i was wondering. I also moved to Georgia my self.
Excellent job with the videos. I hope all is well. I've used your instructions to get me going in the right direction for my project and I thank you for that.
I do have one question though.
Would you know of any resources that I could check out that would help me with being able to search my database using multiple keywords that are typed into a single textbox?
I assume I would have to cycle through the words and split them apart which would allow me to search by each word; however, I don't really know the process for that and how to return the search results and display them into a listbox instead of a datagrid.
Awesome video!, Im using Vb.net 2017 express windows form and connecting to sql server 2017 express, i would like the users when they run the program to be able to select what database to load. I tried setting up a textbox where the users will have to paste the location of the dbase then later on connect with the use of a button.
However, it says value of Strong cannot be converted to connection (which is dim connection as new sqlconnection)
thanks for the class can you send converter of this class to work with Xamarin Android class
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?
Thanks for sharing knowledgeable video. You are an Erudite Person. Can you please help in to use the program to get multiple return parameters.
Niiicee!!!!
Another great tutorial. Are you a programmer by profession?
Hey VB Toolbox, Can you do a series of using Entity Framework since it is the recommended method by MS. Thanks
Great work! How do you call the new connection string?
Trying to replace the hard coded query in Inventory.vb with a stored procedure. Trying to create a new SQLCommand but finding it's not available to me. Any help Thanks
The Stored Procedure will work with standard syntax replacing your hard coded query SQLControl.ExecQuery("EXEC my_stored_proc @param1, @param2") - and you're right - this is the best approach, for sure.
If you can't access the SQLCommand from outside the SQLControl class, just make sure to set the access level to PUBLIC instead of PRIVATE or Dim where it's declared in the class. 🙂
First I want to say Thank You. I have a question that I got a search form with datagridview and I tried IF SQL.RecordCount > 0 do something ELSE do something but it was not working.
Thanks
Great video. I tried adapting your solution to an asp.net web enabled solution but the GridView displays as empty on my first web page when it's displayed. Have you made a similar video illustrating how to do this as a web solution using asp.net rather than forms?
Most of tutorials on UA-cam have videos where written items on screen are not clear that makes difficult for beginners
OK. That's good. Still we have noticed Microsoft said will nomore update version VS Express 10. I liked it a lot but... shouldn't we expect future errors when running a program ? Better, you could trach us using newer versions of VS, right ?
So how do you use the conneciton override you talked about? I would like to open another form and get user name and password info from user and then when they click the Search button it uses that for the connection. However, I run into lots of problems with not initializing the conenciton string on startup.
You can add a new connection string at any point. The important thing is to not immediately run commands against it until it has had enough time to fully initialize. Opening the connection is fast, but even at milliseconds, commands in the same thread may execute faster than the connection opens. Just a thought. Are you testing the connection each time?
Yep I figured it out. What I did was create a global string called strConnect and stored the connect string in that from a form. Then All I had to do is in the LoadGrid() sub add the line SQL = New SQLControl(strConnect). This uses the override constructor that the vid had seen and puts whatever string you have into the DBcon.
Hi, thanks for sharing, great stuff, how about calling stored procedures ?
Hi, Vinny! Not sure if you already saw it, but I just recently released a video on this topic. 🙂
Yes
Great presentation, Thank you very much, I am having an error when filling DBDT, message(DBDT is not a dataset (I am using VS 2019), Can you please help
do you take private online clasess plesae let us know "Please do it"........ Good teachers are real valuable asset and very hard and rare to find
I kinda wish I could, but it's extremely difficult where I live now. Also, I'm terribly out of practice since I haven't coded much in several years.