Database connections to a form
Database connections to a form
Database connections to a form
Database connections to a form
Database connections to a form
Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form
Database connections to a form Database connections to a form
Database connections to a form
Go Back  Xtreme Visual Basic Talk > > > Database connections to a form


Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2013, 02:55 AM
Solar Dragon Solar Dragon is offline
Newcomer
 
Join Date: Feb 2013
Posts: 11
Default Database connections to a form


Hello,
I need help with another form. This form allows quizzes to be taken. The quiz is selected from the top part of the form, using buttons, and then it should load the first question into the bottom part of the form. It then should go through each question in that quiz.

So far, I can only make it load the questions for the first quiz and no other quizzes. Even if I select another quiz, it won't load those questions.

I have a sub routine called "Populate" which loads the first quiz, code below:

Code:
 Private Sub Populate()
        Dim QuestionRow As Integer
        Dim QuizRow As Integer
        Dim QuestionNumber As Integer = QNumber
        Dim CurrentQuestion As String

        If QuizIDTxt.Text = 2 Then
            QuizRow = 2
        End If

        CurrentQuestion = QuestionIDTxt.Text
        QuestionRow = QuestionIDTxt.Text - 1
        QuestionManager.Position = QuestionRow

        If QuizRow = 2 Then
            Try
                QuestionTxt.Text = CStr(QuestionTable.Rows(QuestionRow).Item("Question"))
            Catch ex As Exception
                If QuestionTable.Rows(QuestionRow).Item("Question").ToString <> "*" Then
                    QuestionTxt.Text = ""
                End If
            End Try
            Try
                Answer1Txt.Text = CStr(QuestionTable.Rows(QuestionRow).Item("Answer1"))
            Catch ex As Exception
                If QuestionTable.Rows(QuestionRow).Item("Answer1").ToString <> "*" Then
                    Answer1Txt.Text = ""
                End If
            End Try
            Try
                Answer2Txt.Text = CStr(QuestionTable.Rows(QuestionRow).Item("Answer2"))
            Catch ex As Exception
                If QuestionTable.Rows(QuestionRow).Item("Answer2").ToString <> "*" Then
                    Answer2Txt.Text = ""
                End If
            End Try
            Try
                Answer3Txt.Text = CStr(QuestionTable.Rows(QuestionRow).Item("Answer3"))
            Catch ex As Exception
                If QuestionTable.Rows(QuestionRow).Item("Answer3").ToString <> "*" Then
                    Answer3Txt.Text = ""
                End If
            End Try
            Try
                Answer4Txt.Text = CStr(QuestionTable.Rows(QuestionRow).Item("Answer4"))
            Catch ex As Exception
                If QuestionTable.Rows(QuestionRow).Item("Answer4").ToString <> "*" Then
                    Answer4Txt.Text = ""
                End If
            End Try
End Sub
If you need any more bits of code from my project to help you help me, I can do that. If you need any screenshots of my form, I can also do that.

Thanks in advance.
Reply With Quote
  #2  
Old 02-12-2013, 02:53 AM
Solar Dragon Solar Dragon is offline
Newcomer
 
Join Date: Feb 2013
Posts: 11
Default

Okay, please, I need help. I need to get this done by tomorrow. I came here as a last resort. I'm not just asking for help any more, I'm begging for it...

The code for loading my form is here:

Code:
Imports System.Data
Imports System.Data.OleDb
Public Class AssesmentForm
    Dim DatabaseConnection As OleDbConnection
    Dim QuizCommand As OleDbCommand
    Dim QuizAdapter As OleDbDataAdapter
    Dim QuizTable As DataTable
    Dim QuizManager As CurrencyManager
    Dim QuestionManager As CurrencyManager
    Dim QuestionCommand As OleDbCommand
    Dim QuestionAdapter As OleDbDataAdapter
    Dim QuestionTable As DataTable
    Dim MyState As String
    Dim MyBookmark As Integer
    Dim QNumber As Integer = 1

    Private Sub AssesmentForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        DatabaseConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\AssesmentProgram\SchoolAssessments.mdb")

        DatabaseConnection.Open()

        'establish command object
        QuizCommand = New OleDbCommand("SELECT * FROM QuizTable", DatabaseConnection)
        QuestionCommand = New OleDbCommand("SELECT * FROM QuestionTable ORDER BY QuestionID", DatabaseConnection)

        'establish data adapter/data table
        QuestionAdapter = New OleDbDataAdapter()
        QuestionAdapter.SelectCommand = QuestionCommand
        QuestionTable = New DataTable()
        QuestionAdapter.Fill(QuestionTable)

        QuizAdapter = New OleDbDataAdapter()
        QuizAdapter.SelectCommand = QuizCommand
        QuizTable = New DataTable()
        QuizAdapter.Fill(QuizTable)

        'bind controls to data table
        NameTxt.DataBindings.Add("Text", QuizTable, "QuizName")
        Question1Txt.DataBindings.Add("Text", QuizTable, "Question1")
        Question2Txt.DataBindings.Add("Text", QuizTable, "Question2")
        Question3Txt.DataBindings.Add("Text", QuizTable, "Question3")
        Question4Txt.DataBindings.Add("Text", QuizTable, "Question4")
        Question5Txt.DataBindings.Add("Text", QuizTable, "Question5")
        Question6Txt.DataBindings.Add("Text", QuizTable, "Question6")
        Question7Txt.DataBindings.Add("Text", QuizTable, "Question7")
        Question8Txt.DataBindings.Add("Text", QuizTable, "Question8")
        Question9Txt.DataBindings.Add("Text", QuizTable, "Question9")
        Question10Txt.DataBindings.Add("Text", QuizTable, "Question10")
        QuizIDTxt.DataBindings.Add("Text", QuizTable, "QuizID")
        TopicTxt.DataBindings.Add("Text", QuizTable, "QuizTopic")
        DifficultyTxt.DataBindings.Add("Text", QuizTable, "Difficulty")
        DateTxt.DataBindings.Add("Text", QuizTable, "QuizDate")

        QuestionTxt.DataBindings.Add("Text", QuestionTable, "Question")
        Answer1Txt.DataBindings.Add("Text", QuestionTable, "Answer1")
        Answer2Txt.DataBindings.Add("Text", QuestionTable, "Answer2")
        Answer3Txt.DataBindings.Add("Text", QuestionTable, "Answer3")
        Answer4Txt.DataBindings.Add("Text", QuestionTable, "Answer4")
        CorAnsTxt.DataBindings.Add("Text", QuestionTable, "CorrectAnswer")

        QuestionIDTxt.Text = Question1Txt.Text

        'establish currency manager
        QuizManager = DirectCast(Me.BindingContext(QuizTable), CurrencyManager)
        QuestionManager = DirectCast(Me.BindingContext(QuestionTable), CurrencyManager)

        NumberTxt.Text = QNumber

        CorrectBox.Text = "Choose your answer"

        Call Populate()

    End Sub
Basically, it is supposed to load he first question in a quiz, which generally isn't question 1 in the question table of my database. However, it only loads the first question and the arrow buttons make it go through the question table rather than the quiz questions.

I will post screenshots if needed. But, I need to get this done by tomorrow otherwise I have failed my course. Please help. I'm not usually one to ask for help but I am desperate.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Database connections to a form
Database connections to a form
Database connections to a form Database connections to a form
Database connections to a form
Database connections to a form
Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form Database connections to a form
Database connections to a form
Database connections to a form
 
Database connections to a form
Database connections to a form
 
-->