SQL 错误 System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]
SQL ERROR System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]
我希望我的代码 return 一个值,但它 return 是我:
System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]
无法解决并做出正确的输出过程
public static string Test()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var vartest = cnn.Query("select grado from utenti where id='10'");
//var result = output.ToDictionary(row => (string)row.Grado, row => (string)row.Nome ) ; (commento)
//Console.WriteLine(vartest);
cnn.Close();
return vartest.ToString();
}
}
Query
和 Query<T>
return 多行; Query
用于 dynamic
行; Query<T>
用于输入的行。单行有 QueryFirst[<T>]
和 QuerySingle[<T>]
。
如果您正在寻找已知类型的单个值,那么也许:
var vartest = cnn.QuerySingle<string>("select grado from utenti where id='10'");
如果你的意思是你的 return vartest.ToString(); return 给你字符串 "System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]" 这是因为你的 vartest 是一个项目列表,你需要 .ToString 列表中的项目
public static string ManagerFindid()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var select = cnn.Query("select id from utenti");
if (select.Any())
{
return select[0].ToString();
// or do something with all the items in your list
foreach(string value in select)
{
//add value into list view
}
}
else
{
//this is hit when there are no items returned from the select query
return "Nothing Returned from Query";
}
}
您还可以处理 return 从您的 SQL
编辑的多个项目
foreach(string value in select)
{
//do something with current value
}
我希望我的代码 return 一个值,但它 return 是我:
System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]
无法解决并做出正确的输出过程
public static string Test()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var vartest = cnn.Query("select grado from utenti where id='10'");
//var result = output.ToDictionary(row => (string)row.Grado, row => (string)row.Nome ) ; (commento)
//Console.WriteLine(vartest);
cnn.Close();
return vartest.ToString();
}
}
Query
和 Query<T>
return 多行; Query
用于 dynamic
行; Query<T>
用于输入的行。单行有 QueryFirst[<T>]
和 QuerySingle[<T>]
。
如果您正在寻找已知类型的单个值,那么也许:
var vartest = cnn.QuerySingle<string>("select grado from utenti where id='10'");
如果你的意思是你的 return vartest.ToString(); return 给你字符串 "System.Collections.Generic.List`1[Dapper.SqlMapper+DapperRow]" 这是因为你的 vartest 是一个项目列表,你需要 .ToString 列表中的项目
public static string ManagerFindid()
{
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
var select = cnn.Query("select id from utenti");
if (select.Any())
{
return select[0].ToString();
// or do something with all the items in your list
foreach(string value in select)
{
//add value into list view
}
}
else
{
//this is hit when there are no items returned from the select query
return "Nothing Returned from Query";
}
}
您还可以处理 return 从您的 SQL
编辑的多个项目foreach(string value in select)
{
//do something with current value
}