Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Shell Root en 26 Febrero 2010, 03:22 AM

Título: [Aspx.NET] Resultado consulta SQL
Publicado por: Shell Root en 26 Febrero 2010, 03:22 AM
Bueno, tengo una pregunta, que hace rato me anda rondando en la cabeza. Miren, supongamos que tenemos una consulta así:
Código (sql) [Seleccionar]
SELECT [strIdentificacion], [strNombre], [strApellido]
 FROM [Knowledge].[dbo].[tblUsuario]


Ahora cuales son las posibles opciones para ejecutar y recuperar el resultado de la consulta dentro de Aspx.NET

Opción 1:
Código (vbnet) [Seleccionar]
strCmd = New SqlCommand(strSql, strcnn)

strDr = strCmd.ExecuteReader
If strSqlDataReader.Read Then
  txtIdentificacion.Text = strSqlDataReader("strIdentificacion").ToString()
  txtNombre.Text = strSqlDataReader("strNombre").ToString()
  txtApellido.Text = strSqlDataReader("strApellido").ToString()
End If
Título: Re: [Aspx.NET] Resultado consulta SQL
Publicado por: [D4N93R] en 8 Marzo 2010, 15:33 PM
Uhm, me parece que una buena opción para eso es usando un escenario conectado:

Código (csharp) [Seleccionar]
SqlConnection con = new SqlConnection("Aki pones el connectionString");
con.Open();

SqlCommand command = new SqlCommand(TuQueryAki);

SqlAdapter adapter = new SqlAdapter(command, con);

DataTable table = new DataTable()

adapter.Fill(table);


No tengo Visual Studio aquí, así que no se si tenga algún error, jeje :D Espero te ayude eso!