Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Database access through VB.Net

Database access through VB.Net

Scheduled Pinned Locked Moved Visual Basic
databasecsharphelpannouncement
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nyjcr
    wrote on last edited by
    #1

    Hi, Does anybody know where I can find some information on Database access/update/delete through VB.NET I'm creating a program with multiple forms, which needs to select,add,delete record from an ACCESS DB. It is my first DB project and I'm totally lost... Any help I would greatly appreciate it... Thank you, CJ :confused:

    C O 2 Replies Last reply
    0
    • N nyjcr

      Hi, Does anybody know where I can find some information on Database access/update/delete through VB.NET I'm creating a program with multiple forms, which needs to select,add,delete record from an ACCESS DB. It is my first DB project and I'm totally lost... Any help I would greatly appreciate it... Thank you, CJ :confused:

      C Offline
      C Offline
      Chaos Machine
      wrote on last edited by
      #2

      Hello CJ. Ok i am new too in vb.net and i had such a problem to find a solution with Access and VB.NET. BUT i found the answer that you are looking for too. Here it is: ************************* Searching in a database: Dim strConnection As String = OleDbConnection1.ConnectionString (the connectionString will be a string created from the VB when you specify where your database is) Dim connect As New OleDbConnection(strConnection) Dim test As String Dim te As String Dim SQLString As String connect.Open() te = txtAreaToSearch.Text SQLString = "SELECT * from informations WHERE Area =" & "'" & te & "'" Dim cmd As New OleDbCommand(SQLString, connect) Dim reader As OleDbDataReader = cmd.ExecuteReader() While reader.Read() txtCouncilName.Text = reader.GetValue(1) 'gets the value of the first attribute in your databse eg postCodeOfTheArea End While reader.Close() connect.Close() In this example you will need a OleDbConnection1 and a OdbcCommand1 objects. Also the following must be put at the start : Imports System Imports System.Data Imports System.Data.OleDb What the example does is to search in a database on the TABLE informations for an AREA with the name that is in a TEXTBOX called txtAreaToSearch. ********************************** Deleting an entry Dim SQLStringUpdateKeys As String Dim SQLStringUpdateArea As String Dim icount As Integer Dim icount1 As Integer Dim strConnection As String = OleDbConnection1.ConnectionString Dim connect As New OleDbConnection(strConnection) Dim inputOption As Integer inputOption = MsgBox("Are you sure you want to delete this record", MsgBoxStyle.OKCancel, "Are you sure?") If inputOption = 1 Then connect.Open() On Error Resume Next SQLStringUpdateArea = "DELETE FROM informations WHERE Area = '" & txtAreaName.Text & "'" Dim cmd1 As New OleDbCommand(SQLStringUpdateArea, connect) icount1 = cmd1.ExecuteNonQuery connect.Close() MessageBox.Show("Records Deleted in table: " & icount1) Else Exit Sub End If ************************* inserting a new entry Dim SQLStringUpdateKeys As String Dim SQLStringUpdateArea As String Dim icount As Integer Dim icount1 As Integer Dim strC

      N 1 Reply Last reply
      0
      • N nyjcr

        Hi, Does anybody know where I can find some information on Database access/update/delete through VB.NET I'm creating a program with multiple forms, which needs to select,add,delete record from an ACCESS DB. It is my first DB project and I'm totally lost... Any help I would greatly appreciate it... Thank you, CJ :confused:

        O Offline
        O Offline
        OICU812
        wrote on last edited by
        #3

        Drop an OleDbDataAdapter on a form and use the wizard to connect to the access DB and select a table that you want to view and it will auto-generate all the select, insert, delete and updates for the table. Right click the OleDbDataAdapter and choose Generate DataSet. Add a DataGrid to your form and set the DataSource and DataMember for the DataGrid in the properties Grid. ON the form load event add: Me.OleDbDataAdapter1.Fill(DataSet1) '<-- Assuming you used the default autogenerated names. I suggest reading thru MSDN and just search using DataSet, DataView, BindingManager, BindingManagerBase, CurrencyManager, Calculated Column, Strongly Typed DataSet. You'll need to know what all these things are if you are ever to make anything work. MSDN & Google is your best source really for learning just lookup those words. Don't buy the Book "Programing MicroSoft VisualBasic.Net For MicroSoft Access Databases", it's absolute garbage. Use the "DataForm Wizard" by selecting File|Add new item and look at how it builds a form with navigation buttons. I've been learning all this over the last few weeks, and I must say it's quite FUSTRATING to say the least. It shouldnt be this hard to connect to data and work with it without using third party solutions. I've been playing with the 2005 vb.net Beta and It looks like it's going to be much much easier to work with.

        N 1 Reply Last reply
        0
        • C Chaos Machine

          Hello CJ. Ok i am new too in vb.net and i had such a problem to find a solution with Access and VB.NET. BUT i found the answer that you are looking for too. Here it is: ************************* Searching in a database: Dim strConnection As String = OleDbConnection1.ConnectionString (the connectionString will be a string created from the VB when you specify where your database is) Dim connect As New OleDbConnection(strConnection) Dim test As String Dim te As String Dim SQLString As String connect.Open() te = txtAreaToSearch.Text SQLString = "SELECT * from informations WHERE Area =" & "'" & te & "'" Dim cmd As New OleDbCommand(SQLString, connect) Dim reader As OleDbDataReader = cmd.ExecuteReader() While reader.Read() txtCouncilName.Text = reader.GetValue(1) 'gets the value of the first attribute in your databse eg postCodeOfTheArea End While reader.Close() connect.Close() In this example you will need a OleDbConnection1 and a OdbcCommand1 objects. Also the following must be put at the start : Imports System Imports System.Data Imports System.Data.OleDb What the example does is to search in a database on the TABLE informations for an AREA with the name that is in a TEXTBOX called txtAreaToSearch. ********************************** Deleting an entry Dim SQLStringUpdateKeys As String Dim SQLStringUpdateArea As String Dim icount As Integer Dim icount1 As Integer Dim strConnection As String = OleDbConnection1.ConnectionString Dim connect As New OleDbConnection(strConnection) Dim inputOption As Integer inputOption = MsgBox("Are you sure you want to delete this record", MsgBoxStyle.OKCancel, "Are you sure?") If inputOption = 1 Then connect.Open() On Error Resume Next SQLStringUpdateArea = "DELETE FROM informations WHERE Area = '" & txtAreaName.Text & "'" Dim cmd1 As New OleDbCommand(SQLStringUpdateArea, connect) icount1 = cmd1.ExecuteNonQuery connect.Close() MessageBox.Show("Records Deleted in table: " & icount1) Else Exit Sub End If ************************* inserting a new entry Dim SQLStringUpdateKeys As String Dim SQLStringUpdateArea As String Dim icount As Integer Dim icount1 As Integer Dim strC

          N Offline
          N Offline
          nyjcr
          wrote on last edited by
          #4

          Wow, I was way off.. Let me give this a try... thank you "Chaos Machine"

          1 Reply Last reply
          0
          • O OICU812

            Drop an OleDbDataAdapter on a form and use the wizard to connect to the access DB and select a table that you want to view and it will auto-generate all the select, insert, delete and updates for the table. Right click the OleDbDataAdapter and choose Generate DataSet. Add a DataGrid to your form and set the DataSource and DataMember for the DataGrid in the properties Grid. ON the form load event add: Me.OleDbDataAdapter1.Fill(DataSet1) '<-- Assuming you used the default autogenerated names. I suggest reading thru MSDN and just search using DataSet, DataView, BindingManager, BindingManagerBase, CurrencyManager, Calculated Column, Strongly Typed DataSet. You'll need to know what all these things are if you are ever to make anything work. MSDN & Google is your best source really for learning just lookup those words. Don't buy the Book "Programing MicroSoft VisualBasic.Net For MicroSoft Access Databases", it's absolute garbage. Use the "DataForm Wizard" by selecting File|Add new item and look at how it builds a form with navigation buttons. I've been learning all this over the last few weeks, and I must say it's quite FUSTRATING to say the least. It shouldnt be this hard to connect to data and work with it without using third party solutions. I've been playing with the 2005 vb.net Beta and It looks like it's going to be much much easier to work with.

            N Offline
            N Offline
            nyjcr
            wrote on last edited by
            #5

            Thank you... VB is supposed to be this easy to learn, "foolproof" language...Its not!

            A O 2 Replies Last reply
            0
            • N nyjcr

              Thank you... VB is supposed to be this easy to learn, "foolproof" language...Its not!

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              nyjcr wrote: VB is supposed to be this easy to learn, "foolproof" language...Its not! It's not that the language is hard to learn, IMHO it's not and neither was C++, C#, Java, COBOL, Intel x86 Assembler, TI 9900 Assembler, FORTRAN, ... It's learning how to string together a bunch of statements that makes sense and does what you want that's the hard part. This is true for ANY language.

              1 Reply Last reply
              0
              • N nyjcr

                Thank you... VB is supposed to be this easy to learn, "foolproof" language...Its not!

                O Offline
                O Offline
                OICU812
                wrote on last edited by
                #7

                nyjcr wrote: VB is supposed to be this easy to learn, "foolproof" language...Its not! .Net has made so many thing with VB much easier than previous versions, with the exception of connecting to a plain ol Access database. I miss using vb6 only for data, but im really starting to get the hang of ADO.Net and am starting to like it.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups