problem with latebinding

visualstudio2008 , vb.net2008 , sqlserver2008 India
  • 5 years ago

    hi there i want to make a simple quiz game like kbc in vb.net 2008, for that i have created five buttons in my vb application. and one table in sql as under create table kbc ( Question varchar(100), Option1 varchar(100), Option2 varchar(100), Option3 varchar(100), Option4 varchar(100), Answer varchar(100) )

    and i have inserted these records in this table like this

    insert kbc values('Largest key of ur pc is ','Enter','Backspace','Shift','Space','Space') Collapse | Copy Code insert kbc values(2,'How many muscles are there in a human body ?','206','602','605','208','605')

    now back to my vb form the first button will catch the question and second,third,fourth,fifth buttons will catch options from sql database that i have shown. just as kbc i want to show one question with its four options. and when user click on any button i also want to check the right answer. right answer is also in my kbc table's Answer column. to do that i have written this code Imports System.Data.OleDb Imports System.Data Imports System.Threading Imports System.Data.SqlClient

    Public Class Form1 Dim bm As BindingManagerBase Dim ds As New DataSet Dim adp As OleDb.OleDbDataAdapter

    Sub showrecord(ByVal pos As Integer) Button1.Text = ds.Tables(0).Rows(pos)("Question") Button2.Text = ds.Tables(0).Rows(pos)("Option1") Button3.Text = ds.Tables(0).Rows(pos)("Option2") Button4.Text = ds.Tables(0).Rows(pos)("Option3") Button5.Text = ds.Tables(0).Rows(pos)("Option4") End Sub Private Sub Form1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button1.Text = "" Button2.Text = "" Button3.Text = "" Button4.Text = "" Button5.Text = "" End Sub Private Sub Button2Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim result As DialogResult = MessageBox.Show("Are You Sure", "Millionaire", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) If result = Windows.Forms.DialogResult.OK Then Dim dbCon As OleDbConnection Dim dbCmd As OleDbCommand Dim dbRead As OleDbDataReader dbCon = New OleDbConnection("provider=sqloledb; server=MICROSOF-AE7D21\SQLEXPRESS; database=mahaveer; userid=; password=;Trusted_Connection=yes;") dbCon.Open() dbCmd = New OleDbCommand("select * from kbc", dbCon) adp.Fill(ds, "kbc") Dim temp As String = ds.Tables(0).Rows(0).Item("Answer").ToString dbRead = dbCmd.ExecuteReader While dbRead.Read() 'Dim temp As String = dbRead(6) If Button2.Text = temp Then

    bm.Position += 1 showrecord(bm.Position) Else MsgBox("Sorry Wrong Answer")

    End If End While End If End Sub

    Private Sub Button3Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim result As DialogResult = MessageBox.Show("Are You Sure", "Millionaire", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) If result = Windows.Forms.DialogResult.OK Then Dim dbCon As OleDbConnection Dim dbCmd As OleDbCommand Dim dbRead As OleDbDataReader dbCon = New OleDbConnection("provider=sqloledb; server=MICROSOF-AE7D21\SQLEXPRESS; database=mahaveer; userid=; password=;TrustedConnection=yes;") dbCon.Open() dbCmd = New OleDbCommand("select * from kbc", dbCon) adp.Fill(ds, "kbc") Dim temp As String = ds.Tables(0).Rows(0).Item("Answer").ToString dbRead = dbCmd.ExecuteReader While dbRead.Read() 'Dim temp As String = dbRead(6) If Button3.Text = temp Then bm.Position += 1 showrecord(bm.Position) Else MsgBox("Sorry Wrong Answer")

    End If End While End If End Sub Private Sub Button4Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim result As DialogResult = MessageBox.Show("Are You Sure", "Millionaire", MessageBoxButtons.OKCancel, MessageBo

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic