Visual Basic.NET - store procedure

 
Vista:

store procedure

Publicado por christian hernandez (1 intervención) el 19/12/2011 14:03:06
use Prueba
go

insert into empleado (nombre, edad, puesto)
values ('alejandro', 25, 'programador')
go

select * from empleado
go

delete from empleado where nombre = 'rodrigo'
go

update empleado set edad = 28 where nombre = 'alejandro'
go

reate procedure ver_empleados
as
begin
set nocount on
select * from empleado
set nocount off
end


VB . net

data source = ServidorSQL; initial catalog = BaseDatos; user id = Usuario; password = Contraseña
data source = ServidorSQL; initial catalog = BaseDatos; user id = Usuario; password = Contraseña
Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data

Public Class Class1

Dim strConexion As String = "Data Source=10.1.2.41;Initial Catalog=KIDbox;User ID=kan;Password=kiddev;Pooling=False"
Dim query As String = ""
Dim comando As SqlCommand
Dim conexion As SqlConnection
Dim adaptador As SqlDataAdapter
Public loqsea As String

Imports System.Data
Imports System.Data.SqlClient


Dim sCnn As String
sCnn = "data source = ServidorSQL; initial catalog = BaseDatos; user id = Usuario; password = Contraseña"

Dim sSel As String = "SELECT * FROM NombreTabla"

Dim da As SqlDataAdapter
Dim dt As New DataTable

Try
da = New SqlDataAdapter(sSel, sCnn)
da.Fill(dt)

Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
LabelInfo.Text = String.Format("Total datos en la tabla: {0}", dt.Rows.Count)

Catch ex As Exception
LabelInfo.Text = "Error: " & ex.Message

End Try
using System.Data;
using System.Data.SqlClient;


string sCnn;
sCnn = "data source = ServidorSQL; initial catalog = BaseDatos; user id = Usuario; password = Contraseña";

string sSel = "SELECT * FROM NombreTabla";

SqlDataAdapter da;
DataTable dt = new DataTable();

try
{
da = new SqlDataAdapter(sSel, sCnn);
da.Fill(dt);

this.GridView1.DataSource = dt;
this.GridView1.DataBind();
LabelInfo.Text = String.Format("Total datos en la tabla: {0}", dt.Rows.Count);
}
catch(Exception ex)
{
LabelInfo.Text = "Error: " + ex.Message;
}


ublic Function hola(ByVal NOMBRETAblA As String) As DataTable
Dim tabla As New DataTable
Try
conexion = New SqlConnection(strConexion)

comando = New SqlCommand("busca")
comando.CommandType = CommandType.StoredProcedure
comando.Parameters.AddWithValue("@nombre", NOMBRETAblA)
comando.Connection = conexion
adaptador = New SqlDataAdapter(comando)
adaptador.Fill(tabla)
tabla.TableName = NOMBRETAblA

Catch ex As Exception

conexion.Close()
End Try
Return tabla
End Function


Public Function INSERT(ByVal NOMBRE As String, ByVal edad As Integer, ByVal puesto As String) As DataTable
Dim tabla As New DataTable
Try
conexion = New SqlConnection(strConexion)

comando = New SqlCommand("INSERTA")
comando.CommandType = CommandType.StoredProcedure
comando.Parameters.AddWithValue("@nombre", NOMBRE)
comando.Parameters.AddWithValue("@edad", edad)
comando.Parameters.AddWithValue("@puesto", puesto)
comando.Connection = conexion


adaptador = New SqlDataAdapter(comando)
adaptador.Fill(tabla)
Return tabla

Catch ex As Exception

conexion.Close()
End Try
Return tabla
End Function


Public Function UPDATE(ByVal NOMBRETAblA As String) As DataTable
Dim tabla As New DataTable
Try
conexion = New SqlConnection(strConexion)

comando = New SqlCommand("busca")

comando.CommandType = CommandType.StoredProcedure
comando.Parameters.AddWithValue("@nombre", NOMBRETAblA)
comando.Connection = conexion

adaptador = New SqlDataAdapter(comando)
adaptador.Fill(tabla)
tabla.TableName = NOMBRETAblA

Catch ex As Exception

conexion.Close()
End Try
Return tabla
End Function

Function nombre() As String
Throw New NotImplementedException
End Function

Function edad() As Integer
Throw New NotImplementedException
End Function

Function puesto() As String
Throw New NotImplementedException
End Function

End Class

Imports System.Data

Partial Class _Default
Inherits System.Web.UI.Page
Dim a As New Class1
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim TABLA As DataTable

TABLA = a.hola(TextBox1.Text.ToString)


GridView1.DataSource = TABLA
GridView1.DataBind()
End Sub



Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
a.edad(TextBox3.Text.ToString)
a.nombre(TextBox1.Text)
a.puesto(TextBox2.Text)
Dim TABLA As DataTable

a.INSERT(TextBox1.Text.ToString, CInt(TextBox2.Text), TextBox3.Text)

a.loqsea = TextBox1.Text


TABLA = a.UPDATE(a.loqsea)
GridView1.DataSource = TABLA
GridView1.DataBind()
End Sub

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged

End Sub
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder