MySQL VB.NET Tutorial 9 : How to Link Combobox with Database values

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys in this video I'm going to show you how to link a combo box with your my skill database using your Visual Basic Windows Form application so basically what I want is I want to populate a column from my database in the combo box so let me show you what I want to do exactly first of all I will take a combo box from my toolbox and I will change the font size of this combo box so that we can see the text clearly and now what I want to do is let me show you my database first for example this is my database and I want to show all the names which are there in the name column so all the names from to whatever all the names which are present in the my database this one column all the items from this one column I want to show in the the combo box so how can I show it in my combo box or how can I populate this data in my combo box uh I will show you now so what you need to do in order to populate your combo box directly when the form loads what you need to do is just select your form so just select click anywhere in the form and just double click it and you will reach to the form load event so this event is called whenever your form is loaded so this is the first event which our form is called right and in this form load event I'm going to to write a code to populate all the names from the name column of my database to the combo box so what I'm going to do is I have shown you how to delete a data from the database in the last video so I will just double click this um Buton delete button and I'm going to take all the code inside my delete button click event I will copy all the code from here and I will paste in this form load event because most of the code is reused in this um code for populating the combo box if you don't know the code you can see my last videos I have been showing you how the this code or this skeleton of code works and and if you want you can pause the video and just copy the code from here to the last right and so the first line will remain the same here we in the first two line we are connecting our visual Basics to our myql database by giving our server my skill server credential in here and in the TR catch block we are writing our code and in the catch block we are catching if any exception occurred during the execution of our code and finally when everything is done we are disposing our connection right and in the tri block what we are going to do is we are first of first of all we are opening the connection with the database with this code and in the second line we are writing a query so we will declare a string in which we will pass the query to uh query the database right so this is the string variable I'm uh declaring and in here I'm writing the query to query the database so this query will change for populating your combo box so in here I will write a query select your database name dot your table name so my database name is database here and my table name is e data right so I have written select this star or estx from my database name dot my table name so just write this query and this will be sufficient and then I'm passing this query to the MySQL command and then I'm executing my command using this execute reader code okay and this message box I'm going to delete and before my connection is closed I want to have all the data from my database which is name name which is uh loaded to the combo box right so I will write while reader Dot read so in the while loop what I'm going to do is I'm going to declare a string variable once again so I will write dim s name is equal to and then I will copy my reader variable here which I have declared here right so I will copy this once again dot get string and in the bracket I will write the name of the column from which I want to extract the data so I want to populate all the names so the column of my or the name of my column is name itself so I will write name here so this name is exact ly this name column so this is the name of this column which is name right and what I'm going to do next is I'm going to add this all the names to the combo box so I will write combo box one which is the name of my combo box dot items dot add and I will add all the names which I'm transferring to this string and pass it to my combo box and I will hit enter and this is the code to load your combo box with the MySQL data columns now I will run my program and first of all I will give the username and password connection is correct and now as soon as my form is loaded here you will see all the names from the database is listed or populated in this combo box because we have written our code in the form load event right so let me show you the database these are all the names in the database let's check whether these matches to the database or not so first let me show you the first name so the first name is John second is Mark you can see here John Mark EI Jill and all the names from this name column is populated in the combo box so in this way you can populate your combo box with your database column items using your Visual Basic Windows Form application I hope you have enjoyed this video please rate comment and subscribe and bye for now
Info
Channel: ProgrammingKnowledge
Views: 179,009
Rating: undefined out of 5
Keywords: Visual Basic .NET (Programming Language), Visual Basic (Programming Language), Database (File Format Genre), MySQL (Software), Tutorial (Industry), Software (Musical Album), Deleting, VB.NET, .NET Framework (Programming Language), Microsoft Visual Studio (Software)
Id: -RLEMhGWht0
Channel Id: undefined
Length: 9min 17sec (557 seconds)
Published: Fri Mar 21 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.