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!

КОМЕНТАРІ • 239

  • @k1ng50
    @k1ng50 4 місяці тому +1

    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.

  • @roadie3124
    @roadie3124 2 роки тому +3

    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.

  • @fletcherevans830
    @fletcherevans830 6 років тому +7

    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.

  • @mariusadrianstefan9844
    @mariusadrianstefan9844 Рік тому +2

    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).

  • @randysandberg3755
    @randysandberg3755 7 років тому +1

    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.

  • @grantharrismusic
    @grantharrismusic 2 роки тому +3

    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.

  • @chloekimball536
    @chloekimball536 5 років тому +2

    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!

  • @TheJawtech
    @TheJawtech 7 років тому +1

    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

  • @aungyethu9743
    @aungyethu9743 6 років тому +3

    never seen like the way you teach before, thanks a million....
    wish you could post more of tutorial videos.....

  • @gyustice665
    @gyustice665 7 років тому +4

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

    • @VBToolbox
      @VBToolbox  7 років тому

      Awesome! I'm very happy that they're helping you out. I'm envious that you get to do this for work. :-D

  • @pw3111
    @pw3111 5 місяців тому +1

    Just started this SQL series of videos after your Access ones. Excellent and a lot to learn😊

    • @VBToolbox
      @VBToolbox  5 місяців тому

      Awesome! Very happy you're enjoying the series! SQL server is still my favorite DB to work with. :-)

  • @ranie4877
    @ranie4877 Рік тому +1

    THank you I'm newbie and I really appreciated your work here

  • @skfunnext
    @skfunnext 5 років тому +2

    Thanks for such a sweet explanation - really loved this tutorial and started following your series

  • @leansixsigmabusinessoperat4833
    @leansixsigmabusinessoperat4833 Місяць тому

    Thank you so much .................................!!
    You're doing a great help to the generations of learners

  • @bernardlogador5364
    @bernardlogador5364 6 років тому

    Thanks man, your videos made transitioning from VB6 to .net easy!

  • @wim2561
    @wim2561 6 років тому

    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.

    • @VBToolbox
      @VBToolbox  6 років тому

      I'm very happy that the tutorials have been helpful! :-)

  • @poweroverwhelming1847
    @poweroverwhelming1847 4 роки тому +2

    Your tutorials are too good to exist. 10000/10

  • @VaderFaderVader
    @VaderFaderVader 7 років тому +1

    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!.

    • @VBToolbox
      @VBToolbox  7 років тому

      Hah! Suhweet! :-) I really hope I can deliver this time around. Been trying hard to get caught up after my move.

    • @alvinilmo8577
      @alvinilmo8577 6 років тому

      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

  • @josepachecou
    @josepachecou 7 років тому +1

    Very nice tutorial !!! waiting for the next video, hope comes soon. Thanks a lot.

  • @Cylon39
    @Cylon39 7 років тому +2

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

    • @VBToolbox
      @VBToolbox  7 років тому

      I hope so! Figured I'd best get to it whilst there's a lull in the chaos. :-D

  • @Kicajz7
    @Kicajz7 5 років тому +4

    You just saved my life :) Thank you!

  • @prinschoco
    @prinschoco 4 роки тому

    Thanks I could simplify my code at work a lot using this SQL control class.

  • @rowanbalana8578
    @rowanbalana8578 7 років тому +1

    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

    • @VBToolbox
      @VBToolbox  7 років тому

      Awesome! Always happy to save a life! ;-D

  • @ga7853
    @ga7853 7 років тому

    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.

  • @giorgosnasenas3290
    @giorgosnasenas3290 4 роки тому +1

    Thanks for the tutorials. Great Examples for real work and great for teaching

  • @unicomp5705
    @unicomp5705 5 років тому +1

    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.

    • @VBToolbox
      @VBToolbox  5 років тому

      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!

  • @boundhell3998
    @boundhell3998 7 років тому +2

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

  • @KhalidAfridi1
    @KhalidAfridi1 7 років тому +1

    Thanks a lot, It's really awesome :) so clean and simple.

  • @hassansamara7381
    @hassansamara7381 5 років тому +1

    Thanks for this Simple and reach tutorial.

  • @lbb5754
    @lbb5754 6 років тому +2

    LOVE it - You are a life saver.

  • @rashedkarim1944
    @rashedkarim1944 5 років тому +1

    Your tutorial was very helpful for me. Thanks A lot.

  • @jasonjason8317
    @jasonjason8317 Рік тому +1

    OOOH BUSTED, you gave it away! I saw that WoW folder, lol. Tell me you're not a night elf hunter named legolas :P

    • @VBToolbox
      @VBToolbox  Рік тому

      🤣 That was a looong time ago - but I was a gnome DK, back in the day.

  • @moseslauyihieng8436
    @moseslauyihieng8436 4 роки тому +1

    Thanks for the tutorial! I really like the clean codes using classes, still learning for this skill :)

  • @grossnut
    @grossnut 3 роки тому

    This is an excellent video series - written for VB2010 but I'm following easily in VB2017 SQL server 2017

  • @ataculsabiei
    @ataculsabiei 2 роки тому +2

    wow that was an amazing tutorial, really clear code and well explained

  • @mirkomarkovic1492
    @mirkomarkovic1492 7 років тому

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

  • @yurishizu9
    @yurishizu9 6 років тому

    Thank you this series will help me with my project

  • @anthonypulsejr3521
    @anthonypulsejr3521 3 роки тому +1

    You little marvel! You've gone and made functions into programs!!

    • @VBToolbox
      @VBToolbox  3 роки тому

      🤣 You're killin' me, Anthony!

  • @dougiemui4519
    @dougiemui4519 6 років тому +1

    Welcome back bro. Thumbs up for your efforts!!

  • @maptrking
    @maptrking 4 роки тому +2

    22:24 - THIS IS the BEST THING I'VE HEARD!!! EXACTLY what I'm trying to do... THANK YOU!!!

  • @arjunkhatiwada5148
    @arjunkhatiwada5148 4 роки тому

    Really great!, we expect such more other videos, Thanks a lot.

  • @adriaancoetzee7238
    @adriaancoetzee7238 5 років тому +1

    Great Video, Thank you so much

  • @erikvandervlugt2139
    @erikvandervlugt2139 6 років тому

    Perfectly explained!!!

  • @jackthehammer2245
    @jackthehammer2245 6 років тому

    Nice and smooth tutorial, thanks a lot.

  • @ikramsyahpindolubis5747
    @ikramsyahpindolubis5747 4 роки тому +2

    Never give up

  • @chazbush2934
    @chazbush2934 4 роки тому +1

    Amazing Tutorial Man!

  • @w00blyn
    @w00blyn 7 років тому +1

    awesome tutorial! thanks so much

  • @FERRISHVAC
    @FERRISHVAC 4 роки тому

    Great Resource, Thank You Sir you're the best

  • @psychoLeow
    @psychoLeow 4 роки тому +1

    You are absolutely amazing. :)

  • @jordanlesesne5901
    @jordanlesesne5901 4 роки тому

    Great tutorial! Thank you!

  • @waelhaddad2037
    @waelhaddad2037 5 років тому

    thank you so much , that was really good ,, thanks million times

  • @thiery572
    @thiery572 5 років тому

    Interesting. I'll check out sometimes. Thanks.

  • @voice_of_habib
    @voice_of_habib 7 років тому

    Thank you for nice tutorial.

  • @norteclaportugal8829
    @norteclaportugal8829 4 роки тому

    Great work. Thanks for this great job.

  • @Ruud9010
    @Ruud9010 2 роки тому

    wow, awsome, thanks for this, tomorrow I will start with part 2

  • @Chrissyhof
    @Chrissyhof 3 роки тому

    Great tutorial!! Best I have seen!

  • @harryjames7654
    @harryjames7654 5 років тому

    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!

  • @bradyaero
    @bradyaero 5 років тому

    Well done!

  • @khanglam4261
    @khanglam4261 5 років тому

    You are a legend...

  • @jimohajibolaakinyemi8252
    @jimohajibolaakinyemi8252 6 років тому

    The tutorial is excellent

  • @RTKN197
    @RTKN197 7 років тому +1

    Thanks bro

  • @ahmadhussainwebshare1001
    @ahmadhussainwebshare1001 3 роки тому

    Thx lot Bro . Very helpful tutorial . God bless you

  • @lorenzol707
    @lorenzol707 4 роки тому

    Great Video/ Learned a bunch

  • @clashofclans6089
    @clashofclans6089 7 років тому

    awesome and really helpful code for learners.

  • @justinshears879
    @justinshears879 7 років тому +1

    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 !!!

    • @VBToolbox
      @VBToolbox  7 років тому

      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! :-)

    • @justinshears879
      @justinshears879 7 років тому

      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

  • @yekyawthu219
    @yekyawthu219 2 роки тому

    Excellent Teaching

  • @w00blyn
    @w00blyn 7 років тому +1

    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!

  • @MohammedAbushagor
    @MohammedAbushagor 6 років тому

    Amazing thanks alot

  • @ngotruongson3554
    @ngotruongson3554 6 років тому

    love you bro!

  • @macrobody
    @macrobody 6 років тому +1

    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.

    • @VBToolbox
      @VBToolbox  6 років тому

      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. :-(

  • @sriragkt
    @sriragkt 4 роки тому

    Awesome 👍

  • @jRQLME
    @jRQLME 3 роки тому

    YOU ARE THE VB GOD

  • @ZorroUA
    @ZorroUA 6 років тому

    Cooooool !!!! Thanks )))

  • @claudioabado3317
    @claudioabado3317 3 роки тому

    Thank you!!!!!!!!!!!!!

  • @mscoco1431
    @mscoco1431 4 роки тому

    you are the best thank u

  • @dorothebertens8490
    @dorothebertens8490 5 років тому +1

    Love your tutorials. Do you have any with transaccions, love to learni more on this matter.

  • @kenclemerbaltar532
    @kenclemerbaltar532 7 років тому +1

    nice a new video :)

    • @VBToolbox
      @VBToolbox  7 років тому

      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.

    • @kenclemerbaltar532
      @kenclemerbaltar532 7 років тому +1

      always looking into your new uploads bro keep it up

  • @rafaelreis2632
    @rafaelreis2632 6 років тому

    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!

  • @dorothebertens8490
    @dorothebertens8490 6 років тому

    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 ?

  • @serkancanbaz1
    @serkancanbaz1 Рік тому

    Thanks

  • @DiyintheGhetto
    @DiyintheGhetto 7 років тому +1

    Hello I haven't visit your videos in a while. I been away But again very nice video keep up the great work.

    • @VBToolbox
      @VBToolbox  7 років тому +1

      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. :-)

    • @DiyintheGhetto
      @DiyintheGhetto 7 років тому +1

      I didn't know you moved. I'm soon to move my self.

    • @VBToolbox
      @VBToolbox  7 років тому +1

      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?

    • @DiyintheGhetto
      @DiyintheGhetto 6 років тому

      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.

  • @InaGalaxyFarFarAway
    @InaGalaxyFarFarAway 6 років тому

    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.

  • @Knych-nr4ot
    @Knych-nr4ot 6 років тому

    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)

  • @ahmedabdelwahd9520
    @ahmedabdelwahd9520 5 років тому +1

    thanks for the class can you send converter of this class to work with Xamarin Android class

  • @niloydas6581
    @niloydas6581 7 років тому

    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?

  • @pramodnegi7131
    @pramodnegi7131 7 років тому

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

  • @ypapadim
    @ypapadim 3 роки тому

    Niiicee!!!!

  • @michaelnewman9645
    @michaelnewman9645 7 років тому

    Another great tutorial. Are you a programmer by profession?

  • @bachphi1
    @bachphi1 5 років тому

    Hey VB Toolbox, Can you do a series of using Entity Framework since it is the recommended method by MS. Thanks

  • @derrickwalker3018
    @derrickwalker3018 Рік тому

    Great work! How do you call the new connection string?

  • @edbohnemann5932
    @edbohnemann5932 2 роки тому +2

    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

    • @VBToolbox
      @VBToolbox  2 роки тому +1

      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. 🙂

  • @vule562
    @vule562 7 років тому

    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

  • @jamesoconnor1056
    @jamesoconnor1056 4 роки тому

    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?

  • @lifeonearth7040
    @lifeonearth7040 6 місяців тому +1

    Most of tutorials on UA-cam have videos where written items on screen are not clear that makes difficult for beginners

  • @CarlFritz24
    @CarlFritz24 Рік тому +1

    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 ?

  • @misperry
    @misperry 3 роки тому +1

    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.

    • @BigIslandLavaPioneers
      @BigIslandLavaPioneers 3 роки тому

      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?

    • @misperry
      @misperry 3 роки тому +1

      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.

  • @vinnypassmore5657
    @vinnypassmore5657 Рік тому +1

    Hi, thanks for sharing, great stuff, how about calling stored procedures ?

    • @VBToolbox
      @VBToolbox  Рік тому +1

      Hi, Vinny! Not sure if you already saw it, but I just recently released a video on this topic. 🙂

  • @yeyintkokokoko8600
    @yeyintkokokoko8600 2 роки тому

    Yes

  • @ghassansalem1711
    @ghassansalem1711 2 роки тому

    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

  • @GautamBhatia713284
    @GautamBhatia713284 2 роки тому +1

    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

    • @VBToolbox
      @VBToolbox  2 роки тому

      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.