Results 1 to 6 of 6
  1. #1
    timosilver is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    9

    vb.net to access connection HELP


    Hello,

    i have an access database (wwtbamDB.mdb) with Question1to5table, the table have the ID,Questions,Ans1,Ans2,Ans3,Ans4 column.
    i want to display the content on the appropriate button on a windows form in vb.net.
    Thanks for you help.

    Code:
    Public Class Form1 : Inherits System.Windows.Forms.Form    Dim cn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
    End Class
    
    
    'to open and retrieve
    
    
     Try
                cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_Data Source=C:\Users\Timosoft\Documents\wwtbamDB.mdb;")
                'provider to be used when working with access database
                cn.Open()
                cmd = New OleDbCommand("select * from Question1to5table", cn)
                dr = cmd.ExecuteReader
                While dr.Read()
                    Main1.QuestnBTN1.Text = dr(Questions)
                    Main1.Answerbtn1.Text = dr(Answer1)
                    Main1.Answerbtn2.Text = dr(Answer2)
                    Main1.Answerbtn3.Text = dr(Answer3)
                    Main1.Answerbtn1.Text = dr(Answer4)
                    ' loading data into TextBoxes by column index
                End While
            Catch
            End Try

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    This is not an Access issue. You might post question in a .net forum. Consider: http://forums.aspfree.com/ or http://www.developerbarn.com/forum.php
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742

  4. #4
    timosilver is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    9
    thanks for your reply am finally able to connect my access db to my vb.net project.
    now i need help on how to fill the data item() at random to each of the buttons.


    Answerbtn1
    Answerbtn2
    Answerbtn3
    Answerbtn4


    Main1.QuestnBTN1.Text = ds.Tables("QuestionsandAnswers").Rows(0).Item(1)


    Main1.Answerbtn1.Text = ds.Tables("QuestionsandAnswers").Rows(0).Item(2)
    Main1.Answerbtn2.Text = ds.Tables("QuestionsandAnswers").Rows(0).Item(4)
    Main1.Answerbtn3.Text = ds.Tables("QuestionsandAnswers").Rows(0).Item(3)
    Main1.Answerbtn4.Text = ds.Tables("QuestionsandAnswers").Rows(0).Item(5)

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Again, a VB.net, not Access, question.

    Shouldn't data go in data controls (textbox, combobox, listbox), not a command button? Have no idea what you are trying to do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    timosilver is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    9
    ok thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Create dynamic connection string to Access
    By janwane in forum Access
    Replies: 2
    Last Post: 10-07-2011, 06:56 AM
  2. DAO Recordset Connection for Access 2002
    By creativefusion in forum Programming
    Replies: 5
    Last Post: 08-17-2010, 06:45 PM
  3. Connection to MS Access DB from Windows vista
    By sachin_mt in forum Programming
    Replies: 3
    Last Post: 05-11-2010, 10:31 PM
  4. Replies: 2
    Last Post: 11-10-2009, 02:49 PM
  5. Access data page connection to MySQL
    By dkperez in forum Access
    Replies: 1
    Last Post: 09-29-2009, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums