Reputation: 113
i want get a single Int value from a data set, but i get stuck here, i dont know how convert int= "list int" with LINQ, that i believe is the reason for the exception that throws me in "select d.Field("UserId");".
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");
UPDATE 1: what i want is get a "UserId" value that is int primary key autoincrement from this table after getting the specific row through "UserName" string field
UPDATE 2: the method "obtenerLasColumnasPorIdentificadorDeTabla()" only modified the Sqlite consult, and return the table in DataSet format type.
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;
}
Upvotes: 0
Views: 369
Reputation: 3284
One of two things seems to be happening - I would need to see the entire obtenerLasColumnasPorIdentificadorDeTabla() function to be certain.
You are passing "string" as the fourth parameter into obtenerLasColumnasPorIdentificadorDeTabla(), does this perhaps convert the output to string? If so, .NET cannot implicitly cast sting to INT, you would have to use a convert statement like so:
int userId = Convert.ToInt32("123456");
obtenerLasColumnasPorIdentificadorDeTabla() only returns part of [UserProfile] table, possibly due to input parameters, and is not returning [UserID].
Upvotes: 0