hi gd
I am karthikeyan.
can any one help me how retrive and delete data in vb.net.
I am using access database.

Here how to retrieve data:

Private Sub GetData(ID As Integer)
   Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
   Dim com As OleDbCommand = Nothing
   Dim dr As OleDbDataReader = Nothing

   Try
      con.Open()
      com = New OleDbCommand("SELECT * FROM table WHERE id = " & ID, con)
      dr = com.ExecuteReader(CommandBehavior.CloseConnection)
      If dr.HasRows Then
         dr.Read()
         'assign data to labels and textboxes
         someTextBox.Text = dr.Item("field1")
      End If
      dr.Close()
   Catch ex As Exception
      If con.State = ConnectionState.Open Then
         con.Close()
      End If
   End Try
End Sub

Here's how to update the database:

Private Sub UpdateData(ID As Integer)
   Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
   Dim com As OleDbCommand = Nothing

   Try
      con.Open()
      com = New OleDbCommand("UPDATE table SET field1 = '" & someTextBox.Text & "' WHERE id = " & ID, con)
      com.ExecuteNonQuery()
      con.Close()
   Catch ex As Exception
      If con.State = ConnectionState.Open Then
         con.Close()
      End If
   End Try
End Sub

And finally, here's how to delete from the database:

Private Sub DeleteData(ID As Integer)
   Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;")
   Dim com As OleDbCommand = Nothing

   Try
      con.Open()
      com = New OleDbCommand("DELETE FROM table WHERE id = " & ID, con)
      com.ExecuteNonQuery()
      con.Close()
   Catch ex As Exception
      If con.State = ConnectionState.Open Then
         con.Close()
      End If
   End Try
End Sub

That's all there is to it.

you have to use simple ADO.NET AND SQL commnads

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.