我正在创建一个统一项目(2019版)+ SQLite + VSCode。我在项目文件夹中添加了适当的插件,但仍然有以下错误:
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
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 () {
}}
发布于 2021-03-27 03:19:00
所有这些都不适用于问题中的具体问题,但是当您解决这个问题时,代码也会遇到以下这些问题:
select ifLogin from usario错了。你需要select * from usuario where login = ifLogin。并确保使用参数化查询;该的字符串连接迟早会使数据库崩溃。
此外,如果要查看结果,请使用ExecuteReader()、ExecuteScalar()或Fill()数据集/表。ExecuteNonQuery()是INSERT/UPDATE/DELETE,没有给出SELECT的结果。
https://stackoverflow.com/questions/66827678
复制相似问题