How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

Ash917

I am using a visual studio 2010 and Microsoft Sql server 2005. I want to make the MsgBox("Unable to delete. Equipment Number is not found!", vbInformation, "Error") appear whenever a user enters an incorrect Equip_No. Any help is appreciated. Thanks!

Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

    If MessageBox.Show("Do you really want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
        MsgBox("Operation cancelled")
        Exit Sub
    End If

    'If Command.CommandText = "SELECT FROM dbo.inhouse_hardware_marterfile_tbl WHERE Equip_No = @Equip_No" Then
    Try
        Dim Command As New SqlCommand
        Dim con As New SqlConnection("Server=HPC-107;Database=MRPdb;integrated security= ...")
        con.Open()
        Command.Connection = con
        Command.CommandText = " DELETE FROM dbo.inhouse_hardware_marterfile_tbl WHERE Equip_No = '" & Equip_No.Text & "'"
        Dim da As New SqlDataAdapter
        da.SelectCommand = Command
        da.DeleteCommand = Command
        Command.ExecuteNonQuery()
        msgdeleted()
        con.Close()
    Catch ex As Exception
    End Try

    'Else : MsgBox("Unable to delete. Equipment Number is not found!", vbInformation, "Error")

    'End If
    'Command.Parameters.AddWithValue("@Equip_No", Equip_No.Text)

    Grid()
    ClearTextBoxes()
End Sub
Steve

The ExecuteNonQuery method returns an integer that is the number of rows affected by the command.
In your case, if the number is zero, then you could print your message

 Dim result = Command.ExecuteNonQuery()
 if result = 0 then
    MessageBox.Show("Unable to delete. Equipment Number is not found!")
 else
    MessageBox.Show("Record deleted")
 End if

Said that, please take note that.

  • An SqlDataAdapter is not required in this context.
  • You should use a parameterized query and not a string concatenation

    Dim Command As New SqlCommand
    Dim con As New SqlConnection("Server=HPC-107;Database=MRPdb;integrated security= ...")
    con.Open()
    Command.Connection = con
    Command.CommandText = "DELETE FROM dbo.inhouse_hardware_marterfile_tbl " & _
                          "WHERE Equip_No = @eqno"
    Command.Parameters.AddWithValue("@eqno", Equip_No.Text)
    Dim result = Command.ExecuteNonQuery()
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

From Dev

How can I make a textBox value equal to a datagrivew cell value

From Dev

How can I equip my site with a "vetting" form?

From Dev

How can I make my app appear in UIActivityViewController for text?

From Dev

How can i make my app appear on tablets

From Dev

How can I make my OS appear as if it is running virtualized?

From Dev

How can I make my navbar appear at a certain section?

From Dev

How can I make the value be equal to localstorage or default to "0"

From Dev

I want to check if textbox value is equal to my specific value

From Dev

How can i make a custom made textbox appear when hovering over a button in wpf

From Dev

How can I overload equal method to make different objects have same hashcode value in unordered_multimap in my case

From Dev

How can I make it so that a form's Text property will always equal a textbox's?

From Dev

VBA - How to retrieve value from one TextBox and make it appear in another?

From Dev

How can I make a Msgbox pop up over other application?

From Dev

How can I make my navbar appear on every page in my rails app?

From Dev

Laravel how can I make my video_id column equal to id of my videos table?

From Dev

How can I make a waiting icon appear in the middle of my page with twitter bootstrap 3?

From Dev

How can I make an icon appear next to my title in the <title> tag?

From Dev

How can I make my output appear all on one line with no spaces?

From Dev

How can I make a back button appear only if the user navigated to the page from my website?

From Dev

How can I make an icon appear next to my title in the <title> tag?

From Dev

How can i use the visibility attribute in css to make my submenu appear and reappear?

From Dev

How do I write a swift array that can make the same UIImage appear for all my dynamic cells?

From Dev

How can I make my JS script calls in Magento appear on one line?

From Dev

TkInter: how can I make objects appear on my second window rather than the first?

From Dev

How can I make my HTML elements be equal column width when the window is shrunk in CSS liquid design?

From Dev

How can i save a value in the textbox to a variable

From Dev

How can i get value from textbox?

From Dev

How can i check a value is pasted in Textbox?

Related Related

  1. 1

    How can I make my MsgBox Appear if the Equip_No is not equal to the value in the Equip_no Textbox?

  2. 2

    How can I make a textBox value equal to a datagrivew cell value

  3. 3

    How can I equip my site with a "vetting" form?

  4. 4

    How can I make my app appear in UIActivityViewController for text?

  5. 5

    How can i make my app appear on tablets

  6. 6

    How can I make my OS appear as if it is running virtualized?

  7. 7

    How can I make my navbar appear at a certain section?

  8. 8

    How can I make the value be equal to localstorage or default to "0"

  9. 9

    I want to check if textbox value is equal to my specific value

  10. 10

    How can i make a custom made textbox appear when hovering over a button in wpf

  11. 11

    How can I overload equal method to make different objects have same hashcode value in unordered_multimap in my case

  12. 12

    How can I make it so that a form's Text property will always equal a textbox's?

  13. 13

    VBA - How to retrieve value from one TextBox and make it appear in another?

  14. 14

    How can I make a Msgbox pop up over other application?

  15. 15

    How can I make my navbar appear on every page in my rails app?

  16. 16

    Laravel how can I make my video_id column equal to id of my videos table?

  17. 17

    How can I make a waiting icon appear in the middle of my page with twitter bootstrap 3?

  18. 18

    How can I make an icon appear next to my title in the <title> tag?

  19. 19

    How can I make my output appear all on one line with no spaces?

  20. 20

    How can I make a back button appear only if the user navigated to the page from my website?

  21. 21

    How can I make an icon appear next to my title in the <title> tag?

  22. 22

    How can i use the visibility attribute in css to make my submenu appear and reappear?

  23. 23

    How do I write a swift array that can make the same UIImage appear for all my dynamic cells?

  24. 24

    How can I make my JS script calls in Magento appear on one line?

  25. 25

    TkInter: how can I make objects appear on my second window rather than the first?

  26. 26

    How can I make my HTML elements be equal column width when the window is shrunk in CSS liquid design?

  27. 27

    How can i save a value in the textbox to a variable

  28. 28

    How can i get value from textbox?

  29. 29

    How can i check a value is pasted in Textbox?

HotTag

Archive