Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从SQLite数据库读取值并将值保存在变量中_C#_Sqlite_Unity Container - Fatal编程技术网

C# 从SQLite数据库读取值并将值保存在变量中

C# 从SQLite数据库读取值并将值保存在变量中,c#,sqlite,unity-container,C#,Sqlite,Unity Container,我很难让一些SQLite编程在Unity中工作。我有一个包含两个值的数据库,我想取其中一个值并将其存储为变量。这就是我到目前为止所做的: public IDbConnection _dbc; public IDbCommand _dbcm; public IDataReader _dbr; public string test2 = ""; public int test = 10; _dbc = new SqliteConnection(_constr); _dbc.Open(); _db

我很难让一些SQLite编程在Unity中工作。我有一个包含两个值的数据库,我想取其中一个值并将其存储为变量。这就是我到目前为止所做的:

public IDbConnection _dbc;
public IDbCommand _dbcm;
public IDataReader _dbr;

public string test2 = "";
public int test = 10;

_dbc = new SqliteConnection(_constr);
_dbc.Open();
_dbcm = _dbc.CreateCommand();
_dbcm.CommandText = "SELECT `Name` FROM `Classes` WHERE `HD`='"+test+"'";
_dbr = _dbcm.ExecuteReader();

while( _dbr.Read())
    test2 = _dbr.GetString(0);

print (test2);
_dbr.Close();

我已经对它进行了一些讨论,但到目前为止,打印报告中的test2值没有变化,test2是我想要存储SQLite DB值的变量。

我想知道这是否是由于返回了模糊的结果。如果只需要一个结果,执行标量函数是否会更有用?我不太了解Unity,所以不能说如果结果的类型不正确,GetString()是否会执行隐式转换

下面的示例是一些旧的VisualBasic,但应该说明我所说的内容

Dim sqlConnect As New SQLite.SQLiteConnection
    sqlConnect.ConnectionString = MyStandAloneDB.DBConnStr
    Dim sqlCmd As SQLite.SQLiteCommand = sqlConnect.CreateCommand

        Try
            sqlConnect.Open()
Dim nme As String = CStr(sqlCmd.ExecuteScalar)
            TextDbName.Text = nme
Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            sqlCmd.Dispose()
            sqlConnect.Close()
        End Try

我想知道这是否是一个含糊不清的结果返回的结果。如果只需要一个结果,执行标量函数是否会更有用?我不太了解Unity,所以不能说如果结果的类型不正确,GetString()是否会执行隐式转换

下面的示例是一些旧的VisualBasic,但应该说明我所说的内容

Dim sqlConnect As New SQLite.SQLiteConnection
    sqlConnect.ConnectionString = MyStandAloneDB.DBConnStr
    Dim sqlCmd As SQLite.SQLiteCommand = sqlConnect.CreateCommand

        Try
            sqlConnect.Open()
Dim nme As String = CStr(sqlCmd.ExecuteScalar)
            TextDbName.Text = nme
Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            sqlCmd.Dispose()
            sqlConnect.Close()
        End Try

字段“HD”是什么数据类型?字段“HD”是什么数据类型?谢谢你的帮助,但我想我现在要研究不同的数据库解决方案。谢谢你的帮助,但我想我现在要研究不同的数据库解决方案。