Ver Mensaje Individual
  #6 (permalink)  
Antiguo 14/08/2007, 06:56
Avatar de sagma
sagma
 
Fecha de Ingreso: septiembre-2004
Ubicación: Santa Cruz de la Sierra - Bolivia
Mensajes: 136
Antigüedad: 20 años, 5 meses
Puntos: 1
Re: Como se establece una conexion OleDbConnection

claro mi amigo, yo lo manejo en clases, fijate:

Esta parte lo manejo desde el form.
Código:
    Sub registrar_datos()

        If Not IsNumeric(TextBox1.Text) Then
            MsgBox("El codigo de la Persona debe ser numerico", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox2.Text) = "" Then
            MsgBox("El Nombre de la Persona no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox3.Text) = "" Then
            MsgBox("El Apellidos de la Persona no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox8.Text) = "" Then
            MsgBox("La Cedula de identidad no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox9.Text) = "" Then
            MsgBox("La Direccion no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox10.Text) = "" Then
            MsgBox("La Fecha de nacimiento no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox13.Text) = "" Then
            MsgBox("El tipo de Sangre no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If Trim(TextBox14.Text) = "" Then
            MsgBox("El Numero de NIT no debe ser nula ", MsgBoxStyle.Critical)
            Exit Sub
        End If

        pers.codigo = CInt(TextBox1.Text)
        pers.nro_nit = Trim(TextBox14.Text)
        pers.nombres = Trim(TextBox2.Text)
        pers.apellidos = Trim(TextBox3.Text)
        pers.fecha_ingreso = DateTimePicker1.Value
        pers.inicio_contrato = DateTimePicker2.Value
        pers.fin_contrato = DateTimePicker3.Value
        pers.cedula_identidad = Trim(TextBox8.Text)
        pers.ciudad_ce = ComboBox1.SelectedValue
        pers.direccion = Trim(TextBox9.Text)
        pers.fecha_nac = Trim(TextBox10.Text)
        pers.pais_nac = ComboBox2.SelectedValue
        pers.dpto_nac = ComboBox3.SelectedValue
        pers.nro_celular = Trim(TextBox11.Text)
        pers.nro_telf_fijo = Trim(TextBox12.Text)
        pers.tipo_sangre = Trim(TextBox13.Text)
        pers.sexo = ComboBox5.SelectedValue
        pers.estado_civil = ComboBox6.SelectedValue
        pers.grado_estudio = ComboBox7.SelectedValue
        pers.cargo = ComboBox8.SelectedValue
        pers.cod_prof = ComboBox9.SelectedValue
        pers.cod_estado = ComboBox10.SelectedValue
        pers.tipo_contrato = ComboBox4.SelectedValue

        If pers.existe(pers.codigo) Then
            MsgBox("El codigo para dicha persona, ya existe", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If pers.existe_ci(pers.cedula_identidad) Then
            MsgBox("La Cedula de identidad, ya esta en otra persona", MsgBoxStyle.Critical)
            Exit Sub
        End If

        If pers.existe_nit(pers.nro_nit) Then
            MsgBox("El Nro. de Nit, ya esta en otra persona", MsgBoxStyle.Critical)
            Exit Sub
        End If

        pers.insertar(cnn)

        TextBox2.Text = ""
        TextBox3.Text = ""
        'TextBox4.Text = ""
        'TextBox6.Text = ""
        'TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        TextBox10.Text = ""
        TextBox11.Text = ""
        TextBox12.Text = ""
        TextBox13.Text = ""
        TextBox14.Text = ""

    End Sub

Esta parte del código lo tengo en la clase, persona, ya que inserto los datos de la persona. No es el mismo, que te había puesto con anterioridad, ya que yo solo lo manejo esa parte,
Código:
   Sub insertar(ByVal cnn As OleDbConnection)

        Dim sql As String
        Dim cmd As New OleDbCommand

        sql = "INSERT INTO personal (codigo, nombres, apellidos,fecha_ingreso,inicio_contrato,fin_contrato,cedula_identidad,ciudad_ce , " & _
                                    " direccion,fecha_nac,pais_nac,dpto_nac,nro_celular,nro_telf_fijo,sexo,estado_civil,grado_estudio  , " & _
                                    " tipo_sangre,nro_nit,cargo,cod_prof,cod_estado,tipo_contrato) " & _
              " VALUES (" & codigo & " , '" & nombres & "' , '" & apellidos & "' , " & _
                        " '" & fecha_ingreso & "' , " & _
                        " '" & inicio_contrato & "' , '" & fin_contrato & "' , " & _
                        " '" & cedula_identidad & "' , " & ciudad_ce & " , " & _
                        " '" & direccion & "' , '" & fecha_nac & "' , " & _
                        " " & pais_nac & " , " & dpto_nac & " , " & _
                        " '" & nro_celular & "' , '" & nro_telf_fijo & "' , " & _
                        " " & sexo & ", " & estado_civil & " , " & _
                        " " & grado_estudio & " , '" & tipo_sangre & "' , " & _
                        " '" & nro_nit & "' , " & cargo & " , " & _
                        " " & cod_prof & " , " & cod_estado & " , " & tipo_contrato & " ) "

        cmd.CommandText = sql
        cmd.CommandType = CommandType.Text
        cmd.Connection = cnn

        Try
            cmd.ExecuteNonQuery()
        Catch testado As Exception
            MsgBox(" Error en Insertar en Personal : " & testado.Message)
        End Try

    End Sub
Suerte,
__________________
Sagma -- :arriba: