Results 1 to 5 of 5

Thread: Delete Record from Database

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    NH USA
    Posts
    3

    Delete Record from Database

    I cannot figure out how to delete a row from a database with a VB.NET program. Basically when I have the contents of the row being shown in various textboxes and comboboxes, I want to be able to delete the row that contains that particular information by clicking a button. Can anyone help me?

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    Use SQL, the DELETE statement would do it.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    In case you couldn't figure it out , here you go .
    VB Code:
    1. Public Sub DeleteDB(ByVal DelStr As String, ByVal TableStr As String, ByVal ColumnStr As String)
    2.  
    3.                 Dim SQLText As String = "DELETE FROM " & TableStr & " WHERE " & ColumnStr & " = " & " '" & DelStr & "'" & ""
    4.  
    5.                 Dim objCmd As New OleDb.OleDbCommand(SQLText, MyConnection)
    6.  
    7.                 OpenDB.OpenDB()
    8.  
    9.                 Try
    10.                     If objCmd.ExecuteNonQuery() Then
    11.                         MessageBox.Show("Data Deleted Successfully ...")
    12.                     Else
    13.                         MessageBox.Show("Can't delete Data")
    14.                     End If
    15.  
    16.                 Catch ee As OleDb.OleDbException
    17.                     MessageBox.Show(ee.Message)
    18.                 End Try
    19.                 CloseDB.CloseDB()
    20.             End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2003
    Location
    NH USA
    Posts
    3
    Where do I get the first OpenDB and CloseDB in these statements?

    OpenDB.OpenDB()
    CloseDB.CloseDB()

    VB.net says the variables aren't declared

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by chrisgeleven
    Where do I get the first OpenDB and CloseDB in these statements?
    OpenDB.OpenDB()
    CloseDB.CloseDB()
    VB.net says the variables aren't declared
    Forget about that . These are routines for opening and closing connection . All what you have to do is , declare a connection obj and use it in place of OpenDB and Close that connection when you are done . Tell me if you are stuck .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width