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. add data to database

add data to database

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
4 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.
  • P Offline
    P Offline
    peteyshrew
    wrote on last edited by
    #1

    i think i have made the connection to the database. i need to know how to write the code to add and ID, surname and forename to the database. don't have a clue how to do this. can you help me? (this is the connection) Imports System.Data.OleDb Public Class cust Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Private Sub cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCbank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text End Sub

    T M K 3 Replies Last reply
    0
    • P peteyshrew

      i think i have made the connection to the database. i need to know how to write the code to add and ID, surname and forename to the database. don't have a clue how to do this. can you help me? (this is the connection) Imports System.Data.OleDb Public Class cust Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Private Sub cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCbank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text End Sub

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      I guess a Google[^] would have returned you a lot of results. Have a look at Link1[^] Link 2[^]

      1 Reply Last reply
      0
      • P peteyshrew

        i think i have made the connection to the database. i need to know how to write the code to add and ID, surname and forename to the database. don't have a clue how to do this. can you help me? (this is the connection) Imports System.Data.OleDb Public Class cust Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Private Sub cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCbank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text End Sub

        M Offline
        M Offline
        manni_n
        wrote on last edited by
        #3

        well its jst the simple addiing in data base... here is the code for u.. check it out....and put yr table name wherever specified tablename and make required changes Imports System Imports System.data.oledb Inherits System.Windows.Forms.Form public class form1 Dim da As New OleDbDataAdapter("select * from tablename", "provider=microsoft.jet.oledb.4.0;data source=|DataDirectory|\PCbank.mdb;") Dim ds As New DataSet Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim i As Integer Dim str As String 'under insert button Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Try cn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=GIVE PATH of yr mdb file;") cn.Open() cmd = New OleDbCommand("insert into tablename(ID,surname,forename) values('" & (TextBox1.Text) & "','" & (TextBox2.Text) & "','" & (TextBox3.Text) & ")", cn) i = cmd.ExecuteNonQuery() MsgBox("record inserted") Catch ex As Exception End Try cn.Close()

        1 Reply Last reply
        0
        • P peteyshrew

          i think i have made the connection to the database. i need to know how to write the code to add and ID, surname and forename to the database. don't have a clue how to do this. can you help me? (this is the connection) Imports System.Data.OleDb Public Class cust Public conn As OleDbConnection Public comm As OleDbCommand Public dr As OleDbDataReader Public da As OleDbDataAdapter Private Sub cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load conn = New OleDbConnection 'establishes that conn is a new connection conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCbank.mdb" 'the name of the connection (name of the database on the end) conn.Open() 'opens the connection comm = New OleDbCommand 'establishes that comm is a new command comm.Connection = conn 'the connection for the command is the connection specified comm.CommandType = CommandType.Text 'the commands are in text End Sub

          K Offline
          K Offline
          klaydze
          wrote on last edited by
          #4

          you can use this code also: Public Function Query(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection, ByRef DS As DataSet) As Integer Dim DA As New OleDb.OleDbDataAdapter(SQL, OLEDBCon) Query = DA.Fill(DS) DA = Nothing End Function Public Function Execute(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection) As Integer Dim com As New OleDb.OleDbCommand(SQL, OLEDBCon) com.ExecuteNonQuery() com = Nothing End Function this is your connection string: Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _ "Data Source=sample.mdb") code of your button save: dim strInsert as string try strInsert="Insert into table1 (field1,fields2...) Values('" & txt1 & "','" & txt2 & "'...)" con.open Execute(strInsert,con) MsgBox("Record Saved") con.close end try my code is simple.:)

          Don't block the drive way of all the newbies in programming. :))

          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