Consulting

Results 1 to 6 of 6

Thread: Sending data to Access via VB

  1. #1
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location

    Sending data to Access via VB

    I am trying to send data to an Access database, can anyone see this issue below??

    [vba]

    Inherits System.Windows.Forms.Form
    'The System.Data.OleDb.OleDbConnection class represents a connection to OleDb data source
    Dim cn As OleDbConnection
    'The System.Data.OleDb.OleDbCommand class represents a SQL statement or stored procedure
    'that is executed in a database by an OLE DB provider.
    Dim cmd As OleDbCommand
    Dim icount As Integer
    Dim str, EmpID As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    EmpID = txtEmpID.Text 'empId
    Try
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\track.mdb;User ID=Admin;")
    cn.Open()
    str = "insert into tblTrack ([EmpID]) values ('" & EmpID & "')"

    cmd = New OleDbCommand(str, cn)
    icount = cmd.ExecuteNonQuery()
    MessageBox.Show("Congratulations")

    Catch ex As Exception
    MessageBox.Show(ex.ToString())
    End Try
    cn.Close()
    End Sub
    [/vba]

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by debauch
    I am trying to send data to an Access database, can anyone see this issue below??
    [/vba]
    Might HELP if you indicates from WHERE?????

  3. #3
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    FYI, your code is working like a charm for me
    VS2005/VB.NET
    Try to open this table in design mode and
    change options to not prevent the entering an empty value
    in all of the fields, then after you'll run this code
    you can revert these options back
    But better yet to insert values in all fields and
    use for this DataGridView instead of textboxes
    IMHO

    ~'J'~

  4. #4
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    Quote Originally Posted by stanl
    Might HELP if you indicates from WHERE?????
    ????? Why would I include a where clause in an insert query?

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    debauch

    I don't actually think that's what Stan mean's.

    I could be wrong but I think he might be asking where the data is coming from.

  6. #6
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Norie
    debauch
    I could be wrong but I think he might be asking where the data is coming from.
    Yes, that is what I meant. As different db's can have syntax issues inserting data into Access WHERE eas meant to refer to the original data source.

    As a side note, was the code using .net classes in the form?

Posting Permissions

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