Connecting DropDownList to mysql in asp.net using c#

I created aboutcodes data base having reportcard table as show below



If I want to make subject column to load in DropDownList than use below function and call subjectname() Function in Page_Load Function

Here DropDownList1 is Id of DropDownList

public void subjectname()
        {
            string MyConString = "SERVER=localhost;" +
                       "DATABASE=aboutcodes;" +
                       "UID=root;" +
                       "PASSWORD=;";

            /* speed is database name, root is mysql username, test is mysql password */

            using (MySqlConnection connection = new MySqlConnection(MyConString))
            {
                MySqlCommand command = connection.CreateCommand();
                try
                {
                    // open connection
                    connection.Open();
                    // reportcard is mysql table name

                    string cmdText = "SELECT * FROM  `reportcard` ";

                    MySqlCommand cmd = new MySqlCommand(cmdText, connection);

                    MySqlDataReader ddlValues;
                    ddlValues = cmd.ExecuteReader();

                    //subject is column name

                    DropDownList1.DataSource = ddlValues;
                    DropDownList1.DataValueField = "subject";
                    DropDownList1.DataTextField = "subject";
                    DropDownList1.DataBind();
                    //close connection
                    connection.Close();
                }
                catch
                {

                    Label1.Text = "Error In Connection";


                }
            }//end of use of use

        }

22 Comments

  1. Nice article. I feel that u can do it a touch better as this is connected architecture.
    import a dll file called microsoft.applicationblocks.data
    and instead of string cmdText = "SELECT * FROM `reportcard` MySqlCommand cmd = new MySqlCommand(cmdText, connection);
    MySqlDataReader ddlValues;
    ddlValues = cmd.ExecuteReader();
    u can use
    dataset ds=sqlhelper.executedataset(connectionname,"Query");

    ReplyDelete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.

    ReplyDelete
  3. What is web and digital design?
    The aim of the Master’s course in net and Digital design is that the creation of various skilled profiles with in the web media design space that ar ready to set up, turn out and share through the online communities a replacement generation of content and services in an efficient manner. If you want courses oriented any details to contact us: Digital Marketing Training Institute

    ReplyDelete
  4. Awesome post, Great to Land here, Keep going, have a great Success!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    we are providing Elearning Company in Chennai since
    Digital Learning Solutions is a big boom to the Students and employee Engagement
    Mycoach Learning is the best certified Elearning Company, which offers
    Mycoach LMS

    ReplyDelete
  5. I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
    Python Training in Chennai
    Python Course in Chennai
    Advanced Java Training in Chennai
    Hadoop Course in Chennai
    Big Data Analytics Courses in Chennai
    Big Data Course in Chennai
    Selenium Training in Chennai
    Python Training in Tambaram


    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This blog is very interesting to read, this contains more useful information, Keep sharing more blogs.
    Array in python
    oops in python
    Python frameworks
    goto statement in python
    Selenium interview questions and answers

    ReplyDelete
  8. Online football betting i99club, one of the world's leading online gambling sites, provides the best prices in football betting
    เว็บแทงบอล


    Ufabet1688 online betting website UEFA Bet is a 100% legal website with all licenses
    ufabet


    UEFA football betting, casino, slots, lottery, direct website 1688, stable financial, 100% UFABET168
    ufa


    Fan wreath shop with free delivery, with pictures before-after sending with receipt.
    พวงหรีด


    Sticking to the COVID-19 situation: Arekorenavi.info
    โควิด


    Online Baccarat FOXZ24 Easy to apply, fast, deposit-withdraw 10 seconds with the system
    บาคาร่า

    ReplyDelete
  9. FOXZ88.NET online casino website Global standard 2020-2021
    คาสิโนออนไลน์


    Betting online gambling reminiscent of UFASCR.COM Baccarat.
    ufabet


    UFABET football betting website, the big brother of all UEFA networks, UFADNA, with an update The first modern system in 2021
    ufa


    Web football i99PRO online lottery casino apply today for free 5000 bonus
    เว็บบอล


    Kardinal Stick Siam - Relx a great promotion. Express delivery in 3 hours.
    relx

    ReplyDelete
  10. Movie-watching websites that are more than movie-watching websites Because we are the number 1 free movie site in Thailand for a long time, including new movies, Thai movies, Western movies, Asian movies, we have all kinds of ways for you Including new series Full of all stories without interstitial ads to keep annoying anymore. One place sa-movie.com.

    Android and IOS operating systems. Watch online movies, Thai movies, Western movies, Asian movies, Cartoon movies, Netflix Movie, Action Movies, Comedy Movies, Crime Movies, Drama Movies, Horror Movies, Adventure Movies, Crash Movies and still have many new movies to watch. You can watch for free anytime, anywhere 24 hours a day at see4k.com.


    GangManga read manga, read manga, read manga online for free, fast loading, clear images in HD quality, all titles, anywhere, anytime, on mobile, tablet, computer. Android and IOS operating systems. Read top comics, action dramas, comedy, adventure, horror and manga. New coming every day to watch many more. Can be read for free anytime anywhere 24 hours a day at gangmanga.com..

    It is no secret that football is among the most popular and widely watched sports. Everybody who likes football tries to find the best platform for free soccer streaming. So, what are the best free sports streaming sites? We are going to answer this question. On this page, you can find a detailed overview of the most widespread soccer streaming websites. Keep on reading and make the best choice for you live24th.me.

    ReplyDelete

Add your comments here

Back to Top