how to use one of mysql database column as variable with VB.NET












-1















I have this table in my mySQl database:




ID First_Name Second_Name Age RFID_Tag Amount_Serve
--------------------------------------------------------------
1 John Smith 28 hdgdYun8JH Small
2 George Mark 35 kdjfHluhHB Big


and have this code for mysql query



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = "Server=localhost;Port=3306;Database=namesdb;Uid=root;Pwd=1234"

Using con As New MySqlConnection(str)
Dim query As String = "select * from namedata where rfid_tag=@rfid"
Dim cm As New MySqlCommand(query, con)

con.Open()
cm.Parameters.Add("@rfid", MySqlDbType.VarChar).Value = TextBox3.Text

Dim rd As MySqlDataReader = cm.ExecuteReader()

' Check if any rows exist
If rd.HasRows = True Then
MessageBox.Show("trun on sm")
Else
MessageBox.Show("Not your time")
End If
End Using
End Sub


what I want is when the rfid tag in textbox3.text equal the rfid tag in table I want to use IF function form if that rfid amount serve Small run python script for small and if big run script for Big
What I think is to replayce:



If rd.HasRows = True Then


to be something like this if Amount_server = Small then



I hope I made it clear any help for this case please.










share|improve this question

























  • Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

    – Tetsuya Yamamoto
    Nov 16 '18 at 7:46













  • Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

    – Mohammad Khaled
    Nov 16 '18 at 9:55











  • @Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

    – Mohammad Khaled
    Nov 16 '18 at 10:17











  • @TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

    – Mohammad Khaled
    Nov 16 '18 at 11:12













  • Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

    – Make StackOverflow Good Again
    Nov 16 '18 at 17:16
















-1















I have this table in my mySQl database:




ID First_Name Second_Name Age RFID_Tag Amount_Serve
--------------------------------------------------------------
1 John Smith 28 hdgdYun8JH Small
2 George Mark 35 kdjfHluhHB Big


and have this code for mysql query



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = "Server=localhost;Port=3306;Database=namesdb;Uid=root;Pwd=1234"

Using con As New MySqlConnection(str)
Dim query As String = "select * from namedata where rfid_tag=@rfid"
Dim cm As New MySqlCommand(query, con)

con.Open()
cm.Parameters.Add("@rfid", MySqlDbType.VarChar).Value = TextBox3.Text

Dim rd As MySqlDataReader = cm.ExecuteReader()

' Check if any rows exist
If rd.HasRows = True Then
MessageBox.Show("trun on sm")
Else
MessageBox.Show("Not your time")
End If
End Using
End Sub


what I want is when the rfid tag in textbox3.text equal the rfid tag in table I want to use IF function form if that rfid amount serve Small run python script for small and if big run script for Big
What I think is to replayce:



If rd.HasRows = True Then


to be something like this if Amount_server = Small then



I hope I made it clear any help for this case please.










share|improve this question

























  • Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

    – Tetsuya Yamamoto
    Nov 16 '18 at 7:46













  • Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

    – Mohammad Khaled
    Nov 16 '18 at 9:55











  • @Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

    – Mohammad Khaled
    Nov 16 '18 at 10:17











  • @TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

    – Mohammad Khaled
    Nov 16 '18 at 11:12













  • Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

    – Make StackOverflow Good Again
    Nov 16 '18 at 17:16














-1












-1








-1








I have this table in my mySQl database:




ID First_Name Second_Name Age RFID_Tag Amount_Serve
--------------------------------------------------------------
1 John Smith 28 hdgdYun8JH Small
2 George Mark 35 kdjfHluhHB Big


and have this code for mysql query



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = "Server=localhost;Port=3306;Database=namesdb;Uid=root;Pwd=1234"

Using con As New MySqlConnection(str)
Dim query As String = "select * from namedata where rfid_tag=@rfid"
Dim cm As New MySqlCommand(query, con)

con.Open()
cm.Parameters.Add("@rfid", MySqlDbType.VarChar).Value = TextBox3.Text

Dim rd As MySqlDataReader = cm.ExecuteReader()

' Check if any rows exist
If rd.HasRows = True Then
MessageBox.Show("trun on sm")
Else
MessageBox.Show("Not your time")
End If
End Using
End Sub


what I want is when the rfid tag in textbox3.text equal the rfid tag in table I want to use IF function form if that rfid amount serve Small run python script for small and if big run script for Big
What I think is to replayce:



If rd.HasRows = True Then


to be something like this if Amount_server = Small then



I hope I made it clear any help for this case please.










share|improve this question
















I have this table in my mySQl database:




ID First_Name Second_Name Age RFID_Tag Amount_Serve
--------------------------------------------------------------
1 John Smith 28 hdgdYun8JH Small
2 George Mark 35 kdjfHluhHB Big


and have this code for mysql query



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = "Server=localhost;Port=3306;Database=namesdb;Uid=root;Pwd=1234"

Using con As New MySqlConnection(str)
Dim query As String = "select * from namedata where rfid_tag=@rfid"
Dim cm As New MySqlCommand(query, con)

con.Open()
cm.Parameters.Add("@rfid", MySqlDbType.VarChar).Value = TextBox3.Text

Dim rd As MySqlDataReader = cm.ExecuteReader()

' Check if any rows exist
If rd.HasRows = True Then
MessageBox.Show("trun on sm")
Else
MessageBox.Show("Not your time")
End If
End Using
End Sub


what I want is when the rfid tag in textbox3.text equal the rfid tag in table I want to use IF function form if that rfid amount serve Small run python script for small and if big run script for Big
What I think is to replayce:



If rd.HasRows = True Then


to be something like this if Amount_server = Small then



I hope I made it clear any help for this case please.







mysql vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 7:51









jmcilhinney

26.5k32033




26.5k32033










asked Nov 16 '18 at 7:44









Mohammad KhaledMohammad Khaled

58




58













  • Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

    – Tetsuya Yamamoto
    Nov 16 '18 at 7:46













  • Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

    – Mohammad Khaled
    Nov 16 '18 at 9:55











  • @Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

    – Mohammad Khaled
    Nov 16 '18 at 10:17











  • @TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

    – Mohammad Khaled
    Nov 16 '18 at 11:12













  • Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

    – Make StackOverflow Good Again
    Nov 16 '18 at 17:16



















  • Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

    – Tetsuya Yamamoto
    Nov 16 '18 at 7:46













  • Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

    – Mohammad Khaled
    Nov 16 '18 at 9:55











  • @Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

    – Mohammad Khaled
    Nov 16 '18 at 10:17











  • @TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

    – Mohammad Khaled
    Nov 16 '18 at 11:12













  • Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

    – Make StackOverflow Good Again
    Nov 16 '18 at 17:16

















Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

– Tetsuya Yamamoto
Nov 16 '18 at 7:46







Something like rd.GetString(5) or rd["Amount_Serve"].ToString() should be enough to retrieve the data and store it inside a string variable.

– Tetsuya Yamamoto
Nov 16 '18 at 7:46















Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

– Mohammad Khaled
Nov 16 '18 at 9:55





Thanks a lot for your reply to help but I want to be clear please..for this rd.GetString(5) I have to replace 5 with Amount_serve column name?

– Mohammad Khaled
Nov 16 '18 at 9:55













@Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

– Mohammad Khaled
Nov 16 '18 at 10:17





@Tetsuya I tried this: If [rd.GetString("Amount_Serve") = "small"] Then . I got this error [Additional information: Invalid attempt to access a field before calling Read()]

– Mohammad Khaled
Nov 16 '18 at 10:17













@TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

– Mohammad Khaled
Nov 16 '18 at 11:12







@TetsuyaYamamoto I want it something like this which can take decision upon mount_serve column with compare rfid column (If (rd.Read()) Then rd.GetString("Amount_Serve") = small MessageBox.Show("OK") Else MessageBox.Show("Not your time") End If)

– Mohammad Khaled
Nov 16 '18 at 11:12















Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

– Make StackOverflow Good Again
Nov 16 '18 at 17:16





Note that what you are after is not a column at all, just a value in a database. Clear questions get more and better answers

– Make StackOverflow Good Again
Nov 16 '18 at 17:16












1 Answer
1






active

oldest

votes


















0














First thanks for @TetsuyaYamamoto to give me the hint!



The solution was like this:



If rd.Read() Then
If rd.GetString(4) = "small" Then


MessageBox.Show("small")


ElseIf rd.GetString(3) = "Big" Then

MessageBox.Show("big")
End If
End If


Thanks for all






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%2f53333457%2fhow-to-use-one-of-mysql-database-column-as-variable-with-vb-net%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First thanks for @TetsuyaYamamoto to give me the hint!



    The solution was like this:



    If rd.Read() Then
    If rd.GetString(4) = "small" Then


    MessageBox.Show("small")


    ElseIf rd.GetString(3) = "Big" Then

    MessageBox.Show("big")
    End If
    End If


    Thanks for all






    share|improve this answer






























      0














      First thanks for @TetsuyaYamamoto to give me the hint!



      The solution was like this:



      If rd.Read() Then
      If rd.GetString(4) = "small" Then


      MessageBox.Show("small")


      ElseIf rd.GetString(3) = "Big" Then

      MessageBox.Show("big")
      End If
      End If


      Thanks for all






      share|improve this answer




























        0












        0








        0







        First thanks for @TetsuyaYamamoto to give me the hint!



        The solution was like this:



        If rd.Read() Then
        If rd.GetString(4) = "small" Then


        MessageBox.Show("small")


        ElseIf rd.GetString(3) = "Big" Then

        MessageBox.Show("big")
        End If
        End If


        Thanks for all






        share|improve this answer















        First thanks for @TetsuyaYamamoto to give me the hint!



        The solution was like this:



        If rd.Read() Then
        If rd.GetString(4) = "small" Then


        MessageBox.Show("small")


        ElseIf rd.GetString(3) = "Big" Then

        MessageBox.Show("big")
        End If
        End If


        Thanks for all







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 13:37

























        answered Nov 16 '18 at 12:19









        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%2f53333457%2fhow-to-use-one-of-mysql-database-column-as-variable-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







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine