简体   繁体   English

VB.Net Ms访问数据库。 如何将行的下一个值一一显示在标签上?

[英]VB.Net Ms Access Database. How can I display next value of a row to a lable one by one?

I'm looking for a way to set the next value of a row into a label without using a Binding Navigator. 我正在寻找一种无需使用绑定导航器即可将行的下一个值设置为标签的方法。 ex: when I click the next button the next username in the username column should appear on the label and keep rolling the names. 例如:当我单击“ 下一步”按钮时,“用户名”列中的下一个用户名应出现在标签上并继续滚动名称。

  • Actually planing to make a quiz so I want to 'roll' the question. 实际上打算进行测验,所以我想“提出”问题。

What I've tried 我尝试过的

I have bound data(ex: usernames) to a label using its property (Data Bindings). 我已使用其属性(数据绑定)将数据(例如:用户名)绑定到标签。 Now how can I display them in the label and with each button press have the next one appear? 现在如何在标签中显示它们,并按下每个按钮都会显示下一个?

OK, this is what did to achieve that on alternative way: but this not working 好的,这是通过替代方法实现的目标:但这不起作用

I'm getting this error >> Syntax error in string in query expression 'tagno='2'. 我收到此错误>>查询表达式'tagno ='2'中字符串的语法错误。 @ line dr = Command.ExecuteReader @行博士= Command.ExecuteReader

The objective is to on button click the count integer will increment and then the query will use count value to find question from database for example if the increment value is 2 then the reader should return question from row where tagno two is. 目的是在按钮上单击,计数整数将增加,然后查询将使用计数值从数据库中查找问题,例如,如果增量值为2,则读者应从标记号为2的行返回问题。

the database table (quest) has following columns, Question Correct_Answer, tagno 数据库表(quest)具有以下几列,Question Correct_Answer,tagno

Dim count As Integer
Private Sub btncontinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncontinue.Click
    Dim conn As New OleDb.OleDbConnection
    Dim olequery As New OleDb.OleDbCommand
    Dim connString As String
    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\" & Application.StartupPath & "\game.accdb"
    conn.ConnectionString = connString
    olequery.Connection = conn
    count += 1
    Dim dr As OleDbDataReader

'quest is the table name. 'quest是表名。 Dim query As String = "select question from quest where tagno='" & count & "" Dim query As String =“从任务中选择问题,其中tagno ='”&count&“”

    cnnOLEDB.Open()
    Dim command As New OleDbCommand(query, cnnOLEDB)
    dr = Command.ExecuteReader
    dr.Read()
    lblquestion.Text = dr(0)
  cnnOLEDB.Close()
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM