none
Make Webservice to Query using WHERE CLAUSE RRS feed

  • Question

  • Hi All,

    I make a Webservice to Query Database like this:

    Public Function GetNoPO(ByVal PO As String) As String
    
            Dim connStr As String = ConfigurationManager.ConnectionStrings("LocalMySqlServer").ConnectionString
            Using con As New MySqlConnection(connStr)
                Using cmd As New MySqlCommand("SELECT * FROM tbpo_queue WHERE NOPO= @PO")
                    Using da As New MySqlDataAdapter
                        cmd.Connection = con
                        da.SelectCommand = cmd
                        cmd.Parameters.Add("@PO", MySqlDbType.VarChar, 50).Value = PO
                        If cmd.Connection.State = ConnectionState.Closed Then
                            cmd.Connection.Open()
                        End If
                        Dim objds As New DataTable
                        da.Fill(objds)
    
                        Return cmd.ExecuteNonQuery()
                    End Using
                End Using
            End Using
        End Function

    please correct if anything goes wrong. there may be something wrong with the Function Query above.

    in the VB.Net Desktop app, I want to do a data search.

    in the VB.Net Desktop app, I want to do a data search. for example in a Textbox. I type Purchase Order Number .. this app will do a search to the database through the Webservice ..

    Thank you...

    • Moved by Xi Jin Monday, December 18, 2017 2:18 AM
    Sunday, December 17, 2017 9:48 AM

Answers

  • Hi Frangky_koe,

    From the code above, you have one function to return cmd.ExecuteNonQuery(), it is the number of rows affected,  For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.  For all other types of statements, the return value is -1. So you just get -1 every time in your code. But you can return the datatable that you search.

     Public Function GetNoPO(ByVal PO As String) As DataTable
            Dim connStr As String = ConfigurationManager.ConnectionStrings("LocalMySqlServer").ConnectionString
            Using con As New MySqlConnection(connStr)
                Using cmd As New MySqlCommand("SELECT * FROM tbpo_queue WHERE NOPO= @PO")
                    Using da As New MySqlDataAdapter
                        cmd.Connection = con
                        da.SelectCommand = cmd
                        cmd.Parameters.Add("@PO", MySqlDbType.VarChar, 50).Value = PO
                        If cmd.Connection.State = ConnectionState.Closed Then
                            cmd.Connection.Open()
                        End If
                        Dim objds As New DataTable
                        da.Fill(objds)
                        Return objds
                    End Using
                End Using
            End Using
        End Function

    Best Regards,

    Cherry





    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Thursday, December 21, 2017 9:03 AM
    • Marked as answer by Frangky_Koe Friday, December 29, 2017 5:48 AM
    • Unmarked as answer by Frangky_Koe Friday, December 29, 2017 5:49 AM
    • Marked as answer by Frangky_Koe Friday, December 29, 2017 5:49 AM
    Monday, December 18, 2017 2:39 AM
    Moderator

All replies