I'm using this query:
string query = "SELECT CAST(FullName AS STRING) FROM Register WHERE ID = 1;
DataTable result = SQLiteDataAccess.MakeQuery(query);
from this SQLite Table. I'm using System.Data and Dapper to access the SQLite database. The following code is used to access the database:
public static DataTable MakeQuery(string query)
{
SQLiteDataReader result;
DataTable datatable = new DataTable();
using (SQLiteConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
cnn.Open();
SQLiteCommand command = new SQLiteCommand(query, cnn);
result = command.ExecuteReader();
datatable.Load(result);
cnn.Close();
}
return datatable;
}
When I try to use the result, for example with this code:
foreach (DataRow record in result.Rows)
{
names.Add((string)record["FullName"]);
}
I get the error "System.ArgumentException: 'Column 'FullName' does not belong to table .'" The following locals window screenshot shows that the name of the column is "CAST(FullName AS STRING)" and not "FullName", and the data type is int64, not string.
It seems that I'm using the wrong syntax for casting data types. It must be different in SQLite because it works in SQL Server. What's the correct query in SQLite? Thanks
Edit: Tried a suggestion in a comment and got this error showing the data type is still Int64.
SELECT CAST(FullName AS STRING) as FullName. As it is, that column has no name, so it's picking the SQL goop as the name