我想从数据集中获得一个Int值,但是我被困在这里,我不知道如何用LINQ转换int =“ list int”,我相信这是引发我进入“ select d.Field”的异常的原因(“用户身份”);”。
var Userid =
from d in con.obtenerLasColumnasPorIdentificadorDeTabla("userprofile", "UserName", TXTnamePaso1.Text, "string").Tables["Tabla"].AsEnumerable()
where d.Field<string>("UserName") == TXTnamePaso1.Text
select d.Field<int>("UserId");
更新1:我想要的是通过“ UserName”字符串字段获取特定的行后,从该表中获取一个“ int”主键自动增量的“ UserId”值
更新2:方法“ obtenerLasColumnasPorIdentificadorDeTabla()”仅修改了Sqlite咨询,并以DataSet格式返回表。
public System.Data.DataSet obtenerLasColumnasPorIdentificadorDeTabla(string nombreTabla, string nombreColumnaParaIdentificar, T valorDeDatoAIdentificar, string tipoDatoValorIdentificar)
{
string comillaIndexDinamica = "";
if (tipoDatoValorIdentificar == "string")
comillaIndexDinamica = "'";
DataSet ds = new DataSet();
ds = ConeccionBaseDatosDirecta.ExecuteQuery("SELECT * FROM " + nombreTabla + " WHERE "+nombreColumnaParaIdentificar+"="+comillaIndexDinamica+valorDeDatoAIdentificar+comillaIndexDinamica+";");
return ds;
}
似乎正在发生两件事之一-我需要确定整个obtenerLasColumnasPorIdentificadorDeTabla()函数是确定的。
您正在将“字符串”作为第四个参数传递到obtenerLasColumnasPorIdentificadorDeTabla()中,这是否会将输出转换为字符串?如果是这样,.NET无法将字符串隐式转换为INT,则必须使用如下的convert语句:
int userId = Convert.ToInt32(“ 123456”);
obtenerLasColumnasPorIdentificadorDeTabla()仅可能由于输入参数而返回[UserProfile]表的一部分,而不返回[UserID]。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句