Results 1 to 4 of 4

Thread: Tutorial.. for Access (Office XP)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    Tutorial.. for Access (Office XP)

    I am on a very tight budget at my home and I need help from someone... I can't afford to go out an spend $50.00 on a book so please help..

    I really need a link (for a beginner) that will show me how to connect to an Acess database using Office XP MS Access and display and edit data.

    Any help you can give me would be greatly appreciated.

    Thanks,

    Anjari

    p.s. Merry Christmas Everyone

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    http://samples.gotdotnet.com/quickstart/winforms/

    Check out the 'Data Access Overview' tutorial

  3. #3
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    data access

    I have some code here i have extracted from a project I am writing which may help. The Connection string is set at start of the project and I have enclosed code which fills the text boxes ( for a very simple data entry screen) with a data reader and then updates using a dataset when the user decides to change the details - maybe it will help.

    regards

    BH

  4. #4
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brisbane Australia
    Posts
    150

    last post

    sorry - forgot the code - here it is

    Module Modules
    Public dbcConnection As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\MyFolder\MyDatabase.MDB;"
    End Module


    Private Sub DataRefresh()
    'refresh the list box based on the current search filter

    Dim sSql As String
    Dim cn As New OleDb.OleDbConnection(dbcConnection)
    cn.Open()

    'set sql string to reflect search criteria
    If txtSearch.Text = "" Then
    sSql = "SELECT ID, UNCode, UNName FROM Unions ORDER BY UNCode"
    Else
    sSql = "SELECT ID, UNCode, UNName FROM Unions WHERE UnCode LIKE '%" & txtSearch.Text & "%' OR UNName LIKE '%" & txtSearch.Text & "%' ORDER BY UNCode"
    End If

    'open the ADO.NET Datareader
    Dim cmd As New OleDb.OleDbCommand(sSql, cn)
    Dim drd As OleDb.OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

    'fill flexgrid here
    lstSearch.Rows = 1
    lstSearch.FormatString = "ID|Code|Name"
    lstSearch.set_ColWidth(0, 960)
    lstSearch.set_ColWidth(1, 1200)
    lstSearch.set_ColWidth(2, 2700)

    Do While drd.Read
    lstSearch.AddItem(drd!ID & vbTab & drd!UNCode & vbTab & drd!UNName)
    Loop
    drd.Close()

    End Sub

    Private Sub DataUpdate()
    'this updates the database with details entered
    Dim sSql As String

    Dim cn As New OleDb.OleDbConnection(dbcConnection)

    'find the selected record
    sSql = "SELECT ID, UNCode, UnName " _
    & "FROM Unions WHERE ID = " & mnCurrentId & " ORDER BY UNCode"

    'open the ADO.NET Dataset
    Dim cmd As New OleDb.OleDbCommand(sSql, cn)

    'open the Data Adapter
    Dim adapter As New OleDb.OleDbDataAdapter(cmd)

    'create a dataset and fill it with the required information
    Dim dsTableTest As New DataSet()
    cn.Open()
    'the following command fills the default values and constraints such as autonumber fields
    adapter.FillSchema(dsTableTest, SchemaType.Mapped, "Unions")
    adapter.Fill(dsTableTest, "Unions")

    Dim row As DataRow

    'if this is add new record then add a blank row
    If dsTableTest.Tables("Unions").Rows.Count = 0 Then
    row = dsTableTest.Tables("Unions").NewRow
    dsTableTest.Tables("Unions").Rows.Add(row)
    End If

    'move thru the table and update it with the new values - only 1 row
    For Each row In dsTableTest.Tables("Unions").Rows
    row("UNName") = txtName.Text
    row("UNCode") = txtCode.Text

    Next

    'create the Command Builder
    Dim cb As New OleDb.OleDbCommandBuilder(adapter)
    adapter = cb.DataAdapter

    'update the records
    Dim nRowsAffected As Integer
    Try

    nRowsAffected = adapter.Update(dsTableTest, "Unions")
    Catch myerror As Exception
    MessageBox.Show(myerror.Message)
    'MessageBox.Show(adapter.UpdateCommand.CommandText)

    Finally
    End Try

    cn.Close()



    End Sub

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