Visual Basic.NET - Mostrar datos en un textbox

 
Vista:
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Brand (5 intervenciones) el 21/03/2016 19:44:42
Hola de nuevo a todos, esta vez tengo un inconveniente al querer mostrar una sola columna de mi base de datos SQL SERVER en un textbox porfavor si me pueden dar una manito
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Private Sub btn_guardar_Click(sender As Object, e As EventArgs) Handles btn_guardar.Click
        Dim b As Integer
        Dim sConnectionString As String _
            = "Data Source=localhost;Initial Catalog=Trisys;Integrated Security=True"
        Dim objConn As New SqlConnection(sConnectionString)
        objConn.Open()
 
        Dim objCmd As New SqlCommand
        objCmd.CommandType = CommandType.Text
        If txt_cant.Text = "" Or txt_cod.Text = "" Or txt_descripcion.Text = "" Then
            MsgBox("LLENE TODOS LOS CAMPOS", 0 + 16, "ERROR DE CARGA DE DATOS")
            Exit Sub
        End If
        objCmd.CommandText = "DECLARE @id_deposito int; select @id_deposito = max(id_deposito) + 1 from deposito;
        INSERT INTO deposito  (id_deposito,nombre,ubicacion,cantidad,codigo,unid_medida,fechaent,origen)
          VALUES (@id_deposito,@descripcion,@ubicacion,@cantidad,@codigo,@medida,@Fechaent,@Origen)"
        objCmd.Parameters.Add("@Descripcion", SqlDbType.VarChar).Value = txt_descripcion.Text
        objCmd.Parameters.Add("@Ubicacion", SqlDbType.VarChar).Value = cmb_ubicacion.SelectedValue
        objCmd.Parameters.Add("@Cantidad", SqlDbType.Int).Value = Convert.ToInt64(txt_cant.Text)
        objCmd.Parameters.Add("@Codigo", SqlDbType.VarChar).Value = txt_cod.Text
        objCmd.Parameters.Add("@Medida", SqlDbType.VarChar).Value = cmb_medida.SelectedItem
        objCmd.Parameters.Add("@Fechaent", SqlDbType.DateTime2).Value = txt_fechaent.Text
        objCmd.Parameters.Add("@Origen", SqlDbType.VarChar).Value = txt_origen.Text
        objCmd.Connection = objConn
        Try
            b = objCmd.ExecuteNonQuery()
            If b > 0 Then
                MessageBox.Show("DATOS  GUARDADOS ")
            End If
        Catch q As Exception
            MessageBox.Show(q.Message, "Error")
        Finally
            objConn.Close()
        End Try
 
    End Sub

esto es de mi boton guardar pero quiero mostrar el maximo valor del id_deposito en un textbox y no lo consigo hacer porfavor si me pueden dar una ayuda gracias
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
sin imagen de perfil

Mostrar datos en un textbox

Publicado por omar (155 intervenciones) el 22/03/2016 13:54:23
Sealiza un select columna * from tabla

y almacena los datos en el grid o un arreglo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-1
Comentar
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Brand (5 intervenciones) el 22/03/2016 17:52:08
gracias por contestar pero agradecería que me ayudes con el código, esa idea ya la tenia pero como implementarlo es lo que me cuesta disculpa la ignorancia
gracias de antemano
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Raul Alejandro (8 intervenciones) el 28/03/2016 23:55:14
Buen Dia:
Haber si te entendí bien, quieres rellenar un text box con el máximo valor que tiene tu campo PK en una tabla. Espero te sirva el siguiente código...
1
2
3
4
5
6
7
8
9
10
Dim Busqueda As String
Busqueda = "Select Max(Id_Deposito) From Deposito"
Dim SC As New SqlCommand(Busqueda, Conexion)
Dim Id As Integer
Dim Idtotal As Integer
Conexion.Open()
Id = SC.ExecuteScalar
Conexion.Close()
Idtotal = Id + 1
textbox1.Text = Idtotal

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Brand (5 intervenciones) el 29/03/2016 20:32:40
Gracias por responder pero me sale un error de que la conexion esta abierta, lo hice asi mismo como lo pusiste pero me sale ese error amigo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Raul Alejandro (8 intervenciones) el 29/03/2016 22:05:07
Podrias colocar el pedazo de código que ajustaste? Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Mostrar datos en un textbox

Publicado por Raul Alejandro (8 intervenciones) el 29/03/2016 22:56:14
Intenta con este, solo ten en cuenta que el dato es tipo string...
1
2
3
4
5
6
7
8
9
10
Conexion.Open()
Dim Consulta As String = "SELECT Max(id_deposito) as maximo FROM deposito"
Dim SC As New SqlCommand(Consulta1, Conexion)
Dim SDR As SqlDataReader = SC.ExecuteReader
If SDR.Read Then
    TextBox1.Text = SDR("maximo")
Else
    TextBox1.Text = "0"
End If
Conexion.Close()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar