Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub Daftar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Daftar.Click
        If Nama.Text = "" Then
            MessageBox.Show("Sila Isikan Nama Anda!", "Amaran!")
        ElseIf Noic.Text = "" Then
            MessageBox.Show("Sila Isikan No I/C Anda!", "Amaran!")
        ElseIf Alamat.Text = "" Then
            MessageBox.Show("Sila Isikan Alamat Anda!", "Amaran!")
        ElseIf Jantina.Text = "" Then
            MessageBox.Show("Sila Pilih Jantina Anda!", "Amaran!")
        ElseIf Notel.Text = "" Then
            MessageBox.Show("Sila Masukkan No Telefon Anda!", "Amaran!")
        Else
            MessageBox.Show("Pastikan Maklumat Yang Diisi Adalah Tepat!", "Amaran!", MessageBoxButtons.YesNo)
            Call Koneksi()
            CMD = New OleDbCommand("Select * from Ahli where IDAhli='" & IDahli.Text & "'", CONN)
            RD = CMD.ExecuteReader
            RD.Read()
            If Not RD.HasRows Then
                Dim simpan As String = "insert into Ahli values ('" & Nama.Text & "','" & Noic.Text & "','" & Alamat.Text & "','" & Umur.Text & "','" & Bangsa.Text & "','" & Notel.Text & "','" & Jantina.Text & "')"
                CMD = New OleDbCommand(simpan, CONN)
                CMD.ExecuteNonQuery()
                MsgBox("Data berhasil di Input", MsgBoxStyle.Information, "Information")
            End If
        End If

    End Sub




Im trying to add data from vb2010 to Microsoft Acces 2013.. Can anyone please help me on this!
Posted
Updated 21-Nov-20 15:26pm
Comments
You accepted my my answer first, then you again rejected it. If that is by mistake, then please accept it again.

"insert into Ahli values ('" & Nama.Text & "','" & Noic.Text & "','" & Alamat.Text & "','" & Umur.Text & "','" & Bangsa.Text & "','" & Notel.Text & "','" & Jantina.Text & "')"
Give the column names in the query (after the table name).
Ensure that the columns in the table match the data provided.
E.g. insert into table1 (A,B,C,D) values (a1,b1,c1,d1)
 
Share this answer
 
Comments
Member 10630083 18-Mar-14 14:35pm    
Still having the same problem,
Its says in this code thats having problem
CMD.ExecuteNonQuery()
Always mention Column Names while inserting like below...
SQL
INSERT INTO TableName(Column1, Column2, Column3) VALUES("somevalue1", "somevalue2", "somevalue3")

As you have not mentioned the column names, so if you are not going to provide all the Columns serially, it would throw you exception. So, be careful and update your code.
 
Share this answer
 
Private Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click

      Try
          Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Datos.accdb;")
              conn.Open()
              Dim command As New OleDbCommand("insert into Empleados([cedula], [tipo_documento], [nombre],[cargo],[genero],[fecha_nac],[ciudad],[direccion],[telefono], [movil] ,[usuario],[password],[email],[Picfoto]) values (@cedula, @tipo_documento, @nombre,@cargo,@genero,fecha_nac,@ciudad,@direccion,@telefono,@movil,@usuario,@password,@email, @foto)", conn)
              With command.Parameters
                  .AddWithValue("@cedula", txtdni.Text)
                  .AddWithValue("@tipo_documento", Cbotipo.Text)
                  .AddWithValue("@nombre", txtNombre.Text)

                  .AddWithValue("@cargo", txtcargo.Text)
                  .AddWithValue("@genero", Cbosexo.Text)

                  .AddWithValue("@fecha_nac", dtFecha.Value)
                  .AddWithValue("@ciudad", txtciudad.Text)
                  .AddWithValue("@direccion", txtDireccion.Text)

                  .AddWithValue("@telefono", txtTelefono.Text)
                  .AddWithValue("@movil", txtmovil.Text)
                  .AddWithValue("@usuario", txtusuario.Text)
                  .AddWithValue("@password", txtpassword.Text)
                  .AddWithValue("@email", txtEmail.Text)


                  Try
                      Dim ms As New System.IO.MemoryStream
                      Dim bmpImage As New Bitmap(PicFoto.Image)

                      bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
                      bytImage = ms.ToArray()
                      ms.Close()
                  Catch ex As Exception
                      MsgBox(ex.ToString)
                  End Try

                  .AddWithValue("@foto", bytImage)

              End With
              command.ExecuteNonQuery()
              MessageBox.Show("New account was successfuly added!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
              command.Dispose()
              conn.Close()

              PicFoto.Image = My.Resources.file
          End Using
      Catch ex As Exception
          MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try

  End Sub
 
Share this answer
 
v2
Comments
Richard Deeming 24-Nov-20 2:11am    
An unexplained and unrelated code-dump is not a "solution" to this question.

You also seem to be storing users' passwords in plain text, which is a big security problem.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900