Windows Presentation Foundation



Los procedimientos almacenados son equivalentes a funciones que se guardan en la base de datos.Por ejemplo:
Creamos un procedimiento almacenado en el SQL Server:

create procedure nuevo_cliente
@id_cliente char(10),
@nombres char(50),
@apellidos char(50),
@direccion char(50),
@telefono char(10),
@ruc char(10),
@dni char(10)
as
insert into cliente values(@id_cliente,@nombres,@apellidos,@direccion,@telefono,@ruc,@dni)

Declaramos en la cabecera los Imports necesarios
Imports System.Data
Imports System.Data.SqlClient


en el evento Load del formulario en VB,por ejemplo , escribimos:

Try
xcon.Open()
Dim com As New SqlCommand("nuevo_cliente")
com.Connection = xcon
com.CommandType = CommandType.StoredProcedure 'Indicamos el tipo de comando
Dim id As Stringid = txtRUC.Text.Substring(0, 4) & txtNombre.Text.Substring(0, 3) & txtApellido.Text.Substring(0, 3)
com.Parameters.Add("@id_cliente", SqlDbType.Char, 10).Value = id
com.Parameters.Add("@nombres", SqlDbType.Char, 50).Value = txtNombre.Text
com.Parameters.Add("@apellidos", SqlDbType.Char, 50).Value = txtApellido.Text
com.Parameters.Add("@direccion", SqlDbType.Char, 50).Value = txtDireccion.Text
com.Parameters.Add("@telefono", SqlDbType.Char, 10).Value = txtTelefono.Text
com.Parameters.Add("@ruc", SqlDbType.Char, 10).Value = txtRUC.Text
com.Parameters.Add("@dni", SqlDbType.Char, 10).Value = txtDNI.Textcom.ExecuteNonQuery()
If xcon.State = ConnectionState.Open Then
xcon.Close()
End If
MsgBox("Cliente agregado con exito", MsgBoxStyle.Information, "Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
xcon.Close()
End Try