border

Miembros:
Mensajes:
Temas:
Online:

Ultimo Miembro:

 
 

  #1 (permalink)  
Antiguo 19-06-2008, 22:38:48
Un Nuevo Amigo
 
Registrado: jun 2008
Posts: 2
abdeel Aun no valorado
Predeterminado guardar en variable el resultado de consulta de sql

tengo el siguiente codigo:

ProtectedSub btnnuevo_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnnuevo.Click

Dim cn AsNew SqlConnection
cn.ConnectionString =
"Data Source=SS1\SQLEXPRESS;" + "Initial Catalog=INTRANET;Integrated Security=True"
Dim cmd AsNew SqlCommand
Dim cons AsInteger = ""
cons = "select (max(idnoproveedor)0)+1 from proveedores"
cmd.CommandText = cons

cmd.Connection = cn

Dim re AsInteger
Using cn
cn.Open()
re = cmd.ExecuteNonQuery()
EndUsing
txtidproveedor.Text = cons.ToString()

txtfecha.Text =
""
txtlegal.Text = ""
txtcomercial.Text = ""
txtfiscal.Text = ""
txtgiro.Text = ""
txtprodyserv.Text = ""
txtrfc.Text = ""
txtfax.Text = ""
txttel.Text = ""
txtweb.Text = ""
txtcontacto.Text = ""
txtpuesto.Text = ""
txtemail.Text = ""
txtnocli.Text = ""
txtcontacto.Text = ""
txtcredito.Text = ""
txtlinea.Text = ""
txtotros.Text = ""

el problema es que no sé como guardar el resultado de una consulta en una variable, para que al momento de presionar en el botón nuevo se cargue automaticamente el numero del nuevo registro.

se que tengo que hecer una consulta que me devuelva el numero mayor del campo idnoproveedor (idnumerodeproveedor), a este resultado le aumento 1 y lo imprimo en la caja de texto, pero sinceramente no soy muy bueno programando y estoy atorado aqui.

de antemano les agradezco la ayuda
Responder Con Cita
  #2 (permalink)  
Antiguo 20-06-2008, 15:43:37
Buena Participación en el Foro
 
Registrado: ago 2005
Ubicación: Santa Cruz - Bolivia
Posts: 71
sagamoal Valoración +2
Contactar con sagamoal a través de MSN Contactar con sagamoal a través de Yahoo
Cool Re: guardar en variable el resultado de consulta de sql

hola que tal, fijate, lo hago de la siguiente manera:

Código:
#Region "Reglas del Negocio"

    Public Function Retorna_Ultimo(ByVal tabla As String, ByVal pktabla As String) As Integer
        Dim Ad As New accesodatos.Operaciones(Command)

        Dim Codigo As Integer
        Command.CommandText = "Select Max(" & pktabla & ") From " & tabla
        Codigo = Command.ExecuteScalar

        Return Codigo

    End Function

#End Region

Suerte.
__________________
sagma
Responder Con Cita
Respuesta


Herramientas
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Trackbacks are habilitado
Pingbacks are habilitado
Refbacks are habilitado



La franja horaria es GMT. Ahora son las 21:37:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
A vBSkinworks Design

Alojado en el servicio Premium de Masquewebs | Diseño mejorado por MasqueWebs

right