You are on page 1of 46

Primera manera de conectarse Aplica 01

Data source = Servidor Initial catalogo = Base de datos Integrated security =True --- Autentificacin Windows

CLICK EN NEPTUNO DATASET Y LO ARRASTRAMOS AL FORM1 DEBIENDO QUEDAR DE LA SIGUIENTE MANERA

EJECUTAMOS EL FORM1 ..

AGREGAMOS OTRA TABLA EMPLEADOS

Y AADIMOS OTROS FORM 02

Segunda manera de conectarse (Modulo) Aplica 02

Modulo Objeto declarar constantes variables enumeraciones listas genricas Tipo de mbito publico

Public cn As New SqlConnection("Data Source=GENESIS-PC; Initial Catalog=Neptuno; integrated security=true") Public da As New SqlDataAdapter Public ds As New DataSet

Agregamos Una Clase :

Y LE PONEMOS POR NOMBRE LECTURABD

AGREGAMOS LAS LIBRERIAS IMPORTS SYSTEM Y LAS CODIFICACIONES CORRESPONDIENTES.

AGREGHAMOS UN CONTROL - DATAGRIWVIEW

CODIFICAMOS EN EL FORMULARIO - LOAD

AGREGAMOS OTROS FORM 2 PARA PROVEEDORES

AGREGAMOS FORMULARIO TABLAS -

String collection editor

COMBOBOX1 PROPIEDADES ------------ITEMS (COLECCIN) Y ESCRIBIMOS LOS NOMBRES SIGUIENTES DE LAS TABLAS

Y CODIFICAMOS EN EL FORM TABLAS TAMBIEN EN EL COMBO TABLAS

Tercera manera de conectarse Aplica 03


Normalmente Se trabaja con procedimientos almacenados Aca trabajaremos con sql select

Crear en la aplicacin

Eliminar app config

Click derecho aplicacin 03 Add New Items

Ojo

<connectionStrings> <add name="cnNeptuno" connectionString="Data Source=B205-13; Initial Catalog=Neptuno; Integrated Security = True" providerName="System.Data.SqlClient"/> </connectionStrings>

Aadimos una clase

Agregamos Una Referencia

Private Sub frmPedidos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dgvDatos.DataSource = obj.LeerTabla("Select * from Proveedores").Tables(0).DefaultView() End Sub

CREACION DE PROCEDIMIENTOS ALMACENADOS


CREATE PROCEDURE usp_ListaClientes as Begin Select IdCliente,NombreCompaa,NombreContacto,Ciudad, Pas, Direccin from Clientes End go exec usp_ListaClientes

CREATE PROCEDURE usp_ListaEmpleados as Begin Select IdEmpleado,Apellidos + '' + Nombre as Vendedor,Apellidos, Nombre, Cargo from Empleados End go

exec usp_ListaEmpleados

}}

GRABAMOS LA VISTA CON EL NOMBRE - VW_Productos

PROCEDIMIENTOS ALMACENADOS - SIN PARAMETROS -

Create Procedure usp_ProductosNombre @Producto VarChar(100) As Begin Select * from VW_Productos Where NombreProducto LIKE @Producto + '%' End

go

Exec usp_ProductosNombre 'Me'

Proyecto Nuevo APLICA PROCEDIMIENTOS

Luego agregamos un App

Entramos al App
<connectionStrings> <add name="cnNeptuno" connectionString="Data Source=.; Initial Catalog=Neptuno;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

Luego Agregamos una clase Neptuno

Proyecto / Add / nueva Referencia System Configuration

Ingresamos a la clase Neptuno y escribimos

Imports System.Data Imports System.Data.SqlClient Imports System.Configuration.ConfigurationManager Public Class Neptuno Public cn As New SqlConnection(ConnectionStrings("cnNeptuno").ConnectionString) Public da As New SqlDataAdapter Public ds As New DataSet Public Function EjecutarSP(ByVal Nombre As String) As DataSet da = New SqlDataAdapter(Nombre, cn) da.SelectCommand.CommandType = CommandType.StoredProcedure ds = New DataSet da.Fill(ds) Return ds End Function

End Class

You might also like