Visual Basic.NET - textbox id autonómico

 
Vista:
sin imagen de perfil

textbox id autonómico

Publicado por SIMON (22 intervenciones) el 29/12/2013 20:02:27
Hola a todos, soy nuevo en programación, uso Microsoft Visual Basic 2010 Express
Tengo la siguiente tabla en Access (Tabla Cliente)

Código = auto numérico en Access
Nombre
Apellidos
Dirección

el formulario de Visual BASIC está enlazado con una base de datos Access 2007, y quiero que el ultimo registro que parece en la base de datos se le sume 1 y me aparezca en el textbox del código cliente.

he intentado con este código pero no funciona (botón Nuevo)
Dim maximo As Integer
Me.Habilitar_Entrada(True)

1
2
3
4
5
6
7
8
9
conexion.Open()
        Dim Agregar As New OleDbCommand
        Agregar.Connection = conexion
        Agregar.CommandType = CommandType.Text
        Agregar.CommandText = "Select MAX(Cod_cli) As maximo FROM Tbla_Cliente"
        maximo = Convert.ToInt32(Agregar.ExecuteScalar()) + 1
        txtCod_Clic.Text = maximo
        Label1.Text = maximo
        conexion.Close()

código fuente del botón guardar.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  'Método para insertar estudiantes
 
        Try
            comandos = New OleDbCommand("insert into Tbla_Cliente (Nom_cli,Ape_cli,Dir_cli,cel_cli,Tel_clie) values (txtNom_cli," & vbCrLf &
                                     "txtApe_cli, txtDir_cli, txtTel_Cli, txtCel_Cli)", conexion)
 
            'comandos.Parameters.AddWithValue("@Cod_cli", txtCod_Clic.Text)
            comandos.Parameters.AddWithValue("@Nom_cli", txtNom_cli.Text)
        comandos.Parameters.AddWithValue("@Ape_cli", txtApe_cli.Text)
        comandos.Parameters.AddWithValue("@Dir_cli", txtDir_cli.Text)
        comandos.Parameters.AddWithValue("@cel_cli", txtCel_Cli.Text)
        comandos.Parameters.AddWithValue("@Tel_clie", txtTel_Cli.Text)
 
        comandos.ExecuteNonQuery()
 
            MsgBox("Guardado correctamente", vbInformation, "Correcto")
 
 
            Me.Habilitar_Entrada(False)
 
        Catch ex As Exception 'En caso de que ocurra una excepción 
            MsgBox("Error al intectar Guardar en la base de datos", vbExclamation, "Error")
        End Try

por favor explicarme con detalles, ya que soy nuevo en V.B.

Que Dios le bendiga a todos, gracias de antemano.
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
Imágen de perfil de Hugo
Val: 50
Ha disminuido su posición en 5 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

textbox id autonómico

Publicado por Hugo (91 intervenciones) el 09/01/2014 19:20:30
Lo que quiere es un contador, por ejemplo:
1
2
3
4
5
6
7
8
9
10
Dim AUTOMATICO AS INTEGER =0
        Dim fila As Integer = DataGridView1.CurrentCellAddress.Y
        Dim Ds As New DataSet
        Dim Da As New SqlClient.SqlDataAdapter("select * from TABLA  order by CODIGO DESC", Cnn)
        Da.Fill(Ds, "TABLA")
        Dim myDataView As DataView = New DataView(Ds.Tables("TABLA"))
        If myDataView.Count > 0 Then
            AUTOMATICO = (myDataView(fila)("CODIGO"))
        END IF
        AUTOMATICO=AUTOM,ATICO+1

Saludos

visita:http://fellebook.com/
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

textbox id autonómico

Publicado por Eliaany Esther (8 intervenciones) el 10/01/2014 01:25:29
gracias a dios me salio con este codigo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Dim maximo As String
 
    limpiarCajas()
 
 
    Dim Agregar As New OleDbCommand
    Agregar.Connection = conexion
    Agregar.CommandType = CommandType.Text
    Agregar.CommandText = "Select MAX(Cod_cli) As maximo FROM Tbla_Cliente"
    maximo = Convert.ToInt32(Agregar.ExecuteScalar()) + 1
    txtCod_Clic.Text = maximo
 
 
 
    txtNom_cli.Focus()

en la base de datos el campo cod_cli, el tipo de datos tiene que ser numérico, para que funcione,

pero gracias
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