 
			
				10/11/2011, 11:55
			
			
			     |  
        |     |    |    Fecha de Ingreso: junio-2011  
						Mensajes: 200
					  Antigüedad: 14 años, 5 meses Puntos: 17     |        |  
  |      Respuesta: insertar datos en tabla access desde vb 2008        te envio mi codigo, pero creo que no me explique bien. si inserta registros. 
te explico. 
tengo una aplicacion que pide un id de una remision y al presionar enter en el textbox hace la busqueda de esa remision y me muestra la fecha de creacion y la hora de creacion en sus respectivos textbox, los otros dos textbox son la hora de salida y la fecha de salida, estas dos son la hora y fecha de mi maquina del momento en que se hace la busqueda.   
enconces mi problema esta en que no busco como hacer que inserte esa fecha y esa hora en la fila de la remision encontrada, es decir como hago una condicion para ello? 
gracias por tu ayuda     
Imports conexion.Conexion 
Imports System.Data.OleDb 
Imports System.Data.SqlClient   
Public Class CapturaRemisiones 
    Inherits System.Windows.Forms.Form 
    Dim conec As New conexion.Conexion 
    Dim remision As String 
    Dim FechaSal As Date 
    Dim HoraSal As String 
    Dim Surtidas As String   
    Private Sub btnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCerrar.Click 
        activa_menu() 
        Me.Close() 
    End Sub   
    Private Sub CapturaRemisiones_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load   
    End Sub   
    Private Sub txtNumero_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumero.KeyPress   
        If Asc(e.KeyChar) = 13 Then 
            conec.conexion() 
            Dim sentenciaSql As String 
            sentenciaSql = String.Format("SELECT FECHA, HORA FROM REMISIONES WHERE NUMREMISION='" + remision + "'") 
            Dim adaptador As New OleDbDataAdapter(sentenciaSql, conec.con) 
            Dim DS As New DataSet 
            adaptador.Fill(DS, "REMISIONES") 
            Dim DT As DataTable 
            DT = DS.Tables.Item("REMISIONES") 
            For Each DR In DT.Rows 
                Try 
                    txtFechaCreacion.Text = DR(0) 
                    txtHoraCreacion.Text = DR(1) 
                    txtFechaSalida.Text = Date.Now.ToString("dd/MM/yyyy") 
                    FechaSal = txtFechaSalida.Text 
                    txtHoraSalida.Text = TimeOfDay 
                    HoraSal = txtHoraSalida.Text 
                Catch ex As InvalidCastException 
                    'response.write(ex.Message) 
                End Try 
            Next 
            If remision = "" Then 
                MsgBox("NO PUEDE CONTINUAR, CAMPO VACIO") 
                txtNumero.Focus() 
            Else 
                btnAceptar.Focus() 
            End If   
            conec.con.Close() 
        End If   
    End Sub   
    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click 
        Dim mensaje As String 
        If (txtFechaCreacion.Text = "") Then 
            MsgBox("NO EXITE ESTA REMISION") 
        Else 
            mensaje = MsgBox("DESEA CAMBIAR LA REMISION COMO  SURTIDA", vbYesNo, "Sistema de Cartera") 
            MsgBox("Fecha " + FechaSal) 
            If (mensaje = vbYes) Then 
                Try 
                    conec.conexion() 
                    Surtidas = "SI" 
                    Dim sentenciaSql As String = "INSERT INTO REMISIONES(SALIO, FECHASAL, HORASAL) values (@SA, @FS, @HS)" 
                    Dim cmd As New OleDb.OleDbCommand(sentenciaSql, conec.con) 
                    cmd.Parameters.AddWithValue("@SA", Surtidas) 
                    cmd.Parameters.AddWithValue("@FS", FechaSal) 
                    cmd.Parameters.AddWithValue("HS", HoraSal) 
                    cmd.ExecuteNonQuery()   
                    conec.con.Close() 
                    txtNumero.Clear() 
                    txtFechaCreacion.Clear() 
                    txtFechaSalida.Clear() 
                    txtHoraSalida.Clear() 
                    txtHoraCreacion.Clear() 
                    txtNumero.Focus() 
                Catch ex As Exception 
                    MsgBox("Ha ocurrido un error") 
                    MessageBox.Show(ex.Message) 
                End Try 
            End If 
        End If 
        conec.con.Close() 
    End Sub   
    Private Sub txtNumero_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumero.TextChanged 
        remision = txtNumero.Text 
    End Sub 
End Class           |