Professional Documents
Culture Documents
1
1
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace DATOS
{
public class ACCESOADATOS
{
public static DataTable mostrarUsuarios()
{
SqlCommand comando =
METODODATOS.crearcomandoproc("UspListaUsuario");
return METODODATOS.ejecutarselect(comando);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DATOS
{
public class configuration
{
static string cadenaconexion =
@"data source=DESKTOP-SD183BQ\MSSQLSERVER01;initial
catalog=DBPRUEBA;integrated security=true";
public static string CadenaConexion
{
get
{
return cadenaconexion;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace DATOS
{
public class METODODATOS
{
public static SqlCommand Crearcomando()
{
string cadenaconexion = configuration.CadenaConexion;
SqlConnection conexion = new SqlConnection();
conexion.ConnectionString = cadenaconexion;
SqlCommand comando = new SqlCommand();
return comando;
}
public static SqlCommand crearcomandoproc(string proc)
{
string cadenaconexion = configuration.CadenaConexion;
SqlConnection conexion = new SqlConnection(cadenaconexion);
SqlCommand comando = new SqlCommand(proc, conexion);
comando.CommandType = CommandType.StoredProcedure;
return comando;
}
public static int ejecutarcomando(SqlCommand comando)
{
try
{
comando.Connection.Open();
return comando.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
comando.Connection.Dispose();
comando.Connection.Close();
}
}
public static DataTable ejecutarselect(SqlCommand comando)
{
DataTable tabla = new DataTable();
try
{
comando.Connection.Open();
SqlDataAdapter adaptador = new SqlDataAdapter();
adaptador.SelectCommand = comando;
adaptador.Fill(tabla);
}
catch
{
throw;
}
finally
{
comando.Connection.Close();
}
return tabla;
}
}
}
using DATOS;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Negocio
{
public class CONSULTADATOS
{
public static DataTable mostrarUsuarios()
{
return ACCESOADATOS.mostrarUsuarios();
}
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 200px">
<table>
</Columns>
</asp:GridView>
</table>
</div>
</form>
</body>
</html>