How to select all column value in mysql with VB.NET





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have table with two columns : "Total" and "Returned" I am trying to take all column values from both but it not work with me. It takes only the first row in the column I want total values in the column



My code :



 Private Sub TotalTextBox_TextChanged(sender As Object, e As EventArgs) Handles TotalTextBox.TextChanged
Dim str As String = "Server=localhost;Port=3306;Database=testdb;Uid=root;Pwd=password"

Using net As New MySqlConnection(str)

Dim totalnet As String = "Select * from testata where Qty_Returned and Total"

Dim cm As New MySqlCommand(totalnet, net)

net.Open()
Dim rdnet As MySqlDataReader = cm.ExecuteReader()

If rdnet.Read() Then
Label16.Text = rdnet.GetString(12) - rdnet.GetString(11)
Else

End If
End Using

End Sub









share|improve this question























  • There is no table in your code.

    – preciousbetine
    Nov 25 '18 at 11:26











  • You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

    – jmcilhinney
    Nov 25 '18 at 11:28











  • That said, how are you expecting to display multiple rows in a single Label?

    – jmcilhinney
    Nov 25 '18 at 11:31











  • By the way, you should be using a

    – jmcilhinney
    Nov 25 '18 at 11:33











  • @jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

    – Mohammad Khaled
    Nov 25 '18 at 11:37


















0















I have table with two columns : "Total" and "Returned" I am trying to take all column values from both but it not work with me. It takes only the first row in the column I want total values in the column



My code :



 Private Sub TotalTextBox_TextChanged(sender As Object, e As EventArgs) Handles TotalTextBox.TextChanged
Dim str As String = "Server=localhost;Port=3306;Database=testdb;Uid=root;Pwd=password"

Using net As New MySqlConnection(str)

Dim totalnet As String = "Select * from testata where Qty_Returned and Total"

Dim cm As New MySqlCommand(totalnet, net)

net.Open()
Dim rdnet As MySqlDataReader = cm.ExecuteReader()

If rdnet.Read() Then
Label16.Text = rdnet.GetString(12) - rdnet.GetString(11)
Else

End If
End Using

End Sub









share|improve this question























  • There is no table in your code.

    – preciousbetine
    Nov 25 '18 at 11:26











  • You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

    – jmcilhinney
    Nov 25 '18 at 11:28











  • That said, how are you expecting to display multiple rows in a single Label?

    – jmcilhinney
    Nov 25 '18 at 11:31











  • By the way, you should be using a

    – jmcilhinney
    Nov 25 '18 at 11:33











  • @jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

    – Mohammad Khaled
    Nov 25 '18 at 11:37














0












0








0








I have table with two columns : "Total" and "Returned" I am trying to take all column values from both but it not work with me. It takes only the first row in the column I want total values in the column



My code :



 Private Sub TotalTextBox_TextChanged(sender As Object, e As EventArgs) Handles TotalTextBox.TextChanged
Dim str As String = "Server=localhost;Port=3306;Database=testdb;Uid=root;Pwd=password"

Using net As New MySqlConnection(str)

Dim totalnet As String = "Select * from testata where Qty_Returned and Total"

Dim cm As New MySqlCommand(totalnet, net)

net.Open()
Dim rdnet As MySqlDataReader = cm.ExecuteReader()

If rdnet.Read() Then
Label16.Text = rdnet.GetString(12) - rdnet.GetString(11)
Else

End If
End Using

End Sub









share|improve this question














I have table with two columns : "Total" and "Returned" I am trying to take all column values from both but it not work with me. It takes only the first row in the column I want total values in the column



My code :



 Private Sub TotalTextBox_TextChanged(sender As Object, e As EventArgs) Handles TotalTextBox.TextChanged
Dim str As String = "Server=localhost;Port=3306;Database=testdb;Uid=root;Pwd=password"

Using net As New MySqlConnection(str)

Dim totalnet As String = "Select * from testata where Qty_Returned and Total"

Dim cm As New MySqlCommand(totalnet, net)

net.Open()
Dim rdnet As MySqlDataReader = cm.ExecuteReader()

If rdnet.Read() Then
Label16.Text = rdnet.GetString(12) - rdnet.GetString(11)
Else

End If
End Using

End Sub






mysql vb.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 11:20









Mohammad KhaledMohammad Khaled

58




58













  • There is no table in your code.

    – preciousbetine
    Nov 25 '18 at 11:26











  • You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

    – jmcilhinney
    Nov 25 '18 at 11:28











  • That said, how are you expecting to display multiple rows in a single Label?

    – jmcilhinney
    Nov 25 '18 at 11:31











  • By the way, you should be using a

    – jmcilhinney
    Nov 25 '18 at 11:33











  • @jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

    – Mohammad Khaled
    Nov 25 '18 at 11:37



















  • There is no table in your code.

    – preciousbetine
    Nov 25 '18 at 11:26











  • You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

    – jmcilhinney
    Nov 25 '18 at 11:28











  • That said, how are you expecting to display multiple rows in a single Label?

    – jmcilhinney
    Nov 25 '18 at 11:31











  • By the way, you should be using a

    – jmcilhinney
    Nov 25 '18 at 11:33











  • @jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

    – Mohammad Khaled
    Nov 25 '18 at 11:37

















There is no table in your code.

– preciousbetine
Nov 25 '18 at 11:26





There is no table in your code.

– preciousbetine
Nov 25 '18 at 11:26













You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

– jmcilhinney
Nov 25 '18 at 11:28





You are only calling Read once so you are only reading one record. There rae plenty of examples around of using a data reader. I suggest that you consult some of them.

– jmcilhinney
Nov 25 '18 at 11:28













That said, how are you expecting to display multiple rows in a single Label?

– jmcilhinney
Nov 25 '18 at 11:31





That said, how are you expecting to display multiple rows in a single Label?

– jmcilhinney
Nov 25 '18 at 11:31













By the way, you should be using a

– jmcilhinney
Nov 25 '18 at 11:33





By the way, you should be using a

– jmcilhinney
Nov 25 '18 at 11:33













@jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

– Mohammad Khaled
Nov 25 '18 at 11:37





@jmcilhinney I want to show the result of total - returned in the label. any suggestion of type of read because I am fresh with mysql.

– Mohammad Khaled
Nov 25 '18 at 11:37












2 Answers
2






active

oldest

votes


















0














Glad you got it working. Just a few suggestions...
Turn on Option Strict for this and all your code.
Comments are inline.



Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
'A Using...End Using block will ensure that your objects that use unmanages
'resources are closed and disposed event if there is an error in the code
Using con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")
'A command object constructor can take an query string and connection as arguments
Using cmd As New MySqlCommand("select sum(Qty_Returned) FROM testdata", con)
'Open the connection at the last possible minute
con.Open()
Dim sqlresult = cmd.ExecuteScalar
Label16.Text = sqlresult.ToString
End Using
Using cmg As New MySqlCommand("select sum(Total) FROM testgdata", con)
Dim sqlresult2 = cmg.ExecuteScalar
Label10.Text = sqlresult2.ToString
End Using
End Using
Label18.Text = (CInt(La
End Sub


Not sure why this code is in this event.






share|improve this answer
























  • Thanks for your valued editing and it worked for me...thanks

    – Mohammad Khaled
    Nov 26 '18 at 6:27



















-1














I got the solution with this code:



 Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As     DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
Dim con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")

Dim cmd As New MySqlCommand
Dim cmg As New MySqlCommand

con.Open()
cmd.Connection = con
cmd.CommandText = "select sum(Qty_Returned) FROM testdata"
Dim sqlresult As Object
sqlresult = cmd.ExecuteScalar
Dim str1 As String
str1 = sqlresult
Label16.Text = str1
cmg.Connection = con
cmg.CommandText = "select sum(Total) FROM testgdata"
Dim sqlresult2 As Object
sqlresult2 = cmg.ExecuteScalar
Dim str2 As String
str2 = sqlresult2
Label10.Text = str2

Label18.Text = Label10.Text - Label16.Text
End Sub





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466924%2fhow-to-select-all-column-value-in-mysql-with-vb-net%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Glad you got it working. Just a few suggestions...
    Turn on Option Strict for this and all your code.
    Comments are inline.



    Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
    'A Using...End Using block will ensure that your objects that use unmanages
    'resources are closed and disposed event if there is an error in the code
    Using con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")
    'A command object constructor can take an query string and connection as arguments
    Using cmd As New MySqlCommand("select sum(Qty_Returned) FROM testdata", con)
    'Open the connection at the last possible minute
    con.Open()
    Dim sqlresult = cmd.ExecuteScalar
    Label16.Text = sqlresult.ToString
    End Using
    Using cmg As New MySqlCommand("select sum(Total) FROM testgdata", con)
    Dim sqlresult2 = cmg.ExecuteScalar
    Label10.Text = sqlresult2.ToString
    End Using
    End Using
    Label18.Text = (CInt(La
    End Sub


    Not sure why this code is in this event.






    share|improve this answer
























    • Thanks for your valued editing and it worked for me...thanks

      – Mohammad Khaled
      Nov 26 '18 at 6:27
















    0














    Glad you got it working. Just a few suggestions...
    Turn on Option Strict for this and all your code.
    Comments are inline.



    Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
    'A Using...End Using block will ensure that your objects that use unmanages
    'resources are closed and disposed event if there is an error in the code
    Using con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")
    'A command object constructor can take an query string and connection as arguments
    Using cmd As New MySqlCommand("select sum(Qty_Returned) FROM testdata", con)
    'Open the connection at the last possible minute
    con.Open()
    Dim sqlresult = cmd.ExecuteScalar
    Label16.Text = sqlresult.ToString
    End Using
    Using cmg As New MySqlCommand("select sum(Total) FROM testgdata", con)
    Dim sqlresult2 = cmg.ExecuteScalar
    Label10.Text = sqlresult2.ToString
    End Using
    End Using
    Label18.Text = (CInt(La
    End Sub


    Not sure why this code is in this event.






    share|improve this answer
























    • Thanks for your valued editing and it worked for me...thanks

      – Mohammad Khaled
      Nov 26 '18 at 6:27














    0












    0








    0







    Glad you got it working. Just a few suggestions...
    Turn on Option Strict for this and all your code.
    Comments are inline.



    Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
    'A Using...End Using block will ensure that your objects that use unmanages
    'resources are closed and disposed event if there is an error in the code
    Using con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")
    'A command object constructor can take an query string and connection as arguments
    Using cmd As New MySqlCommand("select sum(Qty_Returned) FROM testdata", con)
    'Open the connection at the last possible minute
    con.Open()
    Dim sqlresult = cmd.ExecuteScalar
    Label16.Text = sqlresult.ToString
    End Using
    Using cmg As New MySqlCommand("select sum(Total) FROM testgdata", con)
    Dim sqlresult2 = cmg.ExecuteScalar
    Label10.Text = sqlresult2.ToString
    End Using
    End Using
    Label18.Text = (CInt(La
    End Sub


    Not sure why this code is in this event.






    share|improve this answer













    Glad you got it working. Just a few suggestions...
    Turn on Option Strict for this and all your code.
    Comments are inline.



    Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
    'A Using...End Using block will ensure that your objects that use unmanages
    'resources are closed and disposed event if there is an error in the code
    Using con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")
    'A command object constructor can take an query string and connection as arguments
    Using cmd As New MySqlCommand("select sum(Qty_Returned) FROM testdata", con)
    'Open the connection at the last possible minute
    con.Open()
    Dim sqlresult = cmd.ExecuteScalar
    Label16.Text = sqlresult.ToString
    End Using
    Using cmg As New MySqlCommand("select sum(Total) FROM testgdata", con)
    Dim sqlresult2 = cmg.ExecuteScalar
    Label10.Text = sqlresult2.ToString
    End Using
    End Using
    Label18.Text = (CInt(La
    End Sub


    Not sure why this code is in this event.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 26 '18 at 5:23









    MaryMary

    4,4262921




    4,4262921













    • Thanks for your valued editing and it worked for me...thanks

      – Mohammad Khaled
      Nov 26 '18 at 6:27



















    • Thanks for your valued editing and it worked for me...thanks

      – Mohammad Khaled
      Nov 26 '18 at 6:27

















    Thanks for your valued editing and it worked for me...thanks

    – Mohammad Khaled
    Nov 26 '18 at 6:27





    Thanks for your valued editing and it worked for me...thanks

    – Mohammad Khaled
    Nov 26 '18 at 6:27













    -1














    I got the solution with this code:



     Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As     DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
    Dim con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")

    Dim cmd As New MySqlCommand
    Dim cmg As New MySqlCommand

    con.Open()
    cmd.Connection = con
    cmd.CommandText = "select sum(Qty_Returned) FROM testdata"
    Dim sqlresult As Object
    sqlresult = cmd.ExecuteScalar
    Dim str1 As String
    str1 = sqlresult
    Label16.Text = str1
    cmg.Connection = con
    cmg.CommandText = "select sum(Total) FROM testgdata"
    Dim sqlresult2 As Object
    sqlresult2 = cmg.ExecuteScalar
    Dim str2 As String
    str2 = sqlresult2
    Label10.Text = str2

    Label18.Text = Label10.Text - Label16.Text
    End Sub





    share|improve this answer




























      -1














      I got the solution with this code:



       Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As     DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
      Dim con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")

      Dim cmd As New MySqlCommand
      Dim cmg As New MySqlCommand

      con.Open()
      cmd.Connection = con
      cmd.CommandText = "select sum(Qty_Returned) FROM testdata"
      Dim sqlresult As Object
      sqlresult = cmd.ExecuteScalar
      Dim str1 As String
      str1 = sqlresult
      Label16.Text = str1
      cmg.Connection = con
      cmg.CommandText = "select sum(Total) FROM testgdata"
      Dim sqlresult2 As Object
      sqlresult2 = cmg.ExecuteScalar
      Dim str2 As String
      str2 = sqlresult2
      Label10.Text = str2

      Label18.Text = Label10.Text - Label16.Text
      End Sub





      share|improve this answer


























        -1












        -1








        -1







        I got the solution with this code:



         Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As     DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
        Dim con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")

        Dim cmd As New MySqlCommand
        Dim cmg As New MySqlCommand

        con.Open()
        cmd.Connection = con
        cmd.CommandText = "select sum(Qty_Returned) FROM testdata"
        Dim sqlresult As Object
        sqlresult = cmd.ExecuteScalar
        Dim str1 As String
        str1 = sqlresult
        Label16.Text = str1
        cmg.Connection = con
        cmg.CommandText = "select sum(Total) FROM testgdata"
        Dim sqlresult2 As Object
        sqlresult2 = cmg.ExecuteScalar
        Dim str2 As String
        str2 = sqlresult2
        Label10.Text = str2

        Label18.Text = Label10.Text - Label16.Text
        End Sub





        share|improve this answer













        I got the solution with this code:



         Private Sub testdataDataGridView_DataBindingComplete(sender As Object, e As     DataGridViewBindingCompleteEventArgs) Handles testataDataGridView.DataBindingComplete
        Dim con As New MySqlConnection("Server=localhost;Port=3306;Database=testdb; Uid=root;Pwd=1234")

        Dim cmd As New MySqlCommand
        Dim cmg As New MySqlCommand

        con.Open()
        cmd.Connection = con
        cmd.CommandText = "select sum(Qty_Returned) FROM testdata"
        Dim sqlresult As Object
        sqlresult = cmd.ExecuteScalar
        Dim str1 As String
        str1 = sqlresult
        Label16.Text = str1
        cmg.Connection = con
        cmg.CommandText = "select sum(Total) FROM testgdata"
        Dim sqlresult2 As Object
        sqlresult2 = cmg.ExecuteScalar
        Dim str2 As String
        str2 = sqlresult2
        Label10.Text = str2

        Label18.Text = Label10.Text - Label16.Text
        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 19:24









        Mohammad KhaledMohammad Khaled

        58




        58






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466924%2fhow-to-select-all-column-value-in-mysql-with-vb-net%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()