小编FRP*_*P72的帖子

尝试通过C#在数据库上选择时IndexOutOfRangeException

对不起,如果这听起来很无聊.我正在尝试使用C#和SQL Server中的数据库在Unity上制作测验游戏.在这一部分,我试图显示最高分,所以,我做了一个代码来选择数据库中的最大值:

  public bool BuscarScoreFinal1()
    {
        SqlDataReader dataReader = null;

        if (RunQuery(string.Format("SELECT MAX (PlayerScore1) FROM ScoreQuiz1", tableScoreQuiz1), ref dataReader))
        {
            while (dataReader.Read())
            {
                id1 = dataReader.GetInt32(dataReader.GetOrdinal("ID"));
                PlayerName1 = dataReader.GetString(dataReader.GetOrdinal("PlayerName1"));
                PlayerScore1 = dataReader.GetInt32(dataReader.GetOrdinal("PlayerScore1"));

                break;
            }
        }

        if (dataReader != null) dataReader.Close();

        return true;
    }
Run Code Online (Sandbox Code Playgroud)

然后,我尝试在此脚本中的UI文本中打印数据:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UpdateScore : MonoBehaviour
{

    public GameObject Question3Display;
    public Text yourText;
    public bool Buscardados13;

    // Use this for initialization
    void Start()
    {
        Buscardados13 = GameObject.Find("DatabaseConnection").GetComponent<DatabaseInterface>().Connect() == true; …
Run Code Online (Sandbox Code Playgroud)

c# sql sql-server unity-game-engine

5
推荐指数
1
解决办法
85
查看次数

标签 统计

c# ×1

sql ×1

sql-server ×1

unity-game-engine ×1