首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IDataReader Unity + SQLite

IDataReader Unity + SQLite
EN

Stack Overflow用户
提问于 2021-03-27 03:10:06
回答 1查看 129关注 0票数 0

我正在创建一个统一项目(2019版)+ SQLite + VSCode。我在项目文件夹中添加了适当的插件,但仍然有以下错误:

代码语言:javascript
复制
 Assets \ BancoSQLite.cs (33,17): error CS0433: The type 'IDataReader' exists in both 'System.Data, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' and 'netstandard, Version =
2.0.0.0.0 , Culture = neutral, PublicKeyToken = cc7b13ffcd2ddd51 '

我什么都做了,但我想不出解决办法。

脚本SQLite

代码语言:javascript
复制
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Mono.Data.SqliteClient;
using UnityEngine;
using UnityEngine.UI;
public class BancoSQLite : MonoBehaviour {
//private IDbConnection connection;
//private IDbCommand command;
//private IDataReader reader;


public InputField ifLogin;
public InputField ifSenha;
public string senha;
public string login;

private string dbName = "URI=file:SQLiteDB.db";

private void Connection () {
    Debug.Log("Entrou");
    using (var connection = new SqliteConnection (dbName)) {
        connection.Open ();

        using (var command = connection.CreateCommand ()) {
            connection.Open ();

            command.CommandText = "CREATE TABLE IF NOT EXISTS usuario (id INTEGER PRIMARY KEY AUTOINCREMENT, login VARCHAR(30), senha VARCHAR(30));";
            command.ExecuteNonQuery();                
            command.CommandText = "SELECT " + ifLogin + " FROM usuario;";
            //IDataReader login = command.ExecuteNonQuery();
            IDataReader reader = command.ExecuteNonQuery();

            
            Debug.Log(login);
        }
    }
}




// Start is called before the first frame update
void Start () {
    Connection ();

}

// Update is called once per frame
void Update () {

}

}

EN

回答 1

Stack Overflow用户

发布于 2021-03-27 03:19:00

所有这些都不适用于问题中的具体问题,但是当您解决这个问题时,代码也会遇到以下这些问题:

select ifLogin from usario错了。你需要select * from usuario where login = ifLogin。并确保使用参数化查询;该的字符串连接迟早会使数据库崩溃。

此外,如果要查看结果,请使用ExecuteReader()ExecuteScalar()Fill()数据集/表。ExecuteNonQuery()是INSERT/UPDATE/DELETE,没有给出SELECT的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66827678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档