-1

Hi I have this error and it states ... multiple step ole db generated errors. Check each OLE DB status value, if available. No work is done..

Anyone who is an expert in vb.net knows how to fix this code by the way, I am using ms access to as database.........

Imports System.Data.OleDb



Public Class Form2
    Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ADMIN\source\repos\TrooTea1\Database\TrooTea.accdb")
    Private Sub BtnLoginRegister_Click(sender As Object, e As EventArgs) Handles BtnLoginRegister.Click
        Me.Hide()
        Form1.Show()
    End Sub

    Private Sub BtnBrowse_Click(sender As Object, e As EventArgs) Handles BtnBrowse.Click
        Dim pop As OpenFileDialog = New OpenFileDialog
        If pop.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
            PboxRegisterericon.Image = Image.FromFile(pop.FileName)
        End If

    End Sub


    Sub save()
        Try
            conn.Open()
            Dim cmd As New OleDb.OleDbCommand("insert into login('firstname','lastname','username','password','dob','role','status','pic') values (@firstname,@lastname,@username,@password,@dob,@role,@status,@pic)", conn)
            Dim i As New Integer
            cmd.Parameters.Clear()
            cmd.Parameters.AddWithValue("@firstname", TxtFirstname.Text)
            cmd.Parameters.AddWithValue("@lastname", TxtLastname.Text)
            cmd.Parameters.AddWithValue("@username", TxtUsername.Text)
            cmd.Parameters.AddWithValue("@password", TxtPassword.Text)
            cmd.Parameters.AddWithValue("@dob", CDate(DobPicker.Value))
            cmd.Parameters.AddWithValue("@role", ComboRole.Text)
            cmd.Parameters.AddWithValue("@status", CBool(ChkboxStatus.Checked.ToString))

            'image convert to binary formate

            Dim FileSize As New UInt32
            Dim mstream As New System.IO.MemoryStream
            PboxRegisterericon.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
            FileSize = mstream.Length
            mstream.Close()

            cmd.Parameters.AddWithValue("@pic", PboxRegisterericon)

            i = cmd.ExecuteNonQuery
            If i > 0 Then
                MsgBox("New User Register Success !", vbInformation)
            Else
                MsgBox("New User Register Failed !", vbCritical)
            End If



        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        conn.Close()
    End Sub

    Private Sub BtnRegister_Click(sender As Object, e As EventArgs) Handles BtnRegister.Click
        save()

    End Sub
End Class
  • The following may be helpful: https://stackoverflow.com/a/69638011/10024425 – Tu deschizi eu inchid Dec 16 '22 at 19:36
  • 2
    Why this: `CDate(DobPicker.Value)`? The `Value` property of a `DateTimePicker` is already type `Date`, so no cast or conversion is necessary. This is even worse: `CBool(ChkboxStatus.Checked.ToString)`. The `Checked` property of a `CheckBox` is already type `Boolean`, so converting that to a `String` and that back to a `Boolean` is pretty mad. – jmcilhinney Dec 17 '22 at 02:43
  • 1
    A glaring issue is that, when you add the `"@pic"` parameter, the value you provide is the `PictureBox` control. The whole point of saving the `Image` in that control to a `MemoryStream` is so that you can get the data form it to save. Call `ToArray` on your `MemoryStream` to get a `Byte` array and provide that as the parameter value. – jmcilhinney Dec 17 '22 at 02:46

1 Answers1

1

It seems like we're missing part of the error message (the OLE DB status values referred to) that might give better details of what happened.

But I do know that MS Access OLE uses positional parameters with a ? placeholder instead of named parameters. Also, the column names should not be enclosed in single quotes.

Dim cmd As New OleDb.OleDbCommand("insert into login(firstname,lastname,username,password,dob,role,status,pic) values (?, ?, ?, ?, ?, ?, ?, ?)", conn)

...
cmd.Parameters.AddWithValue("?", TxtFirstname.Text)
cmd.Parameters.AddWithValue("?", TxtLastname.Text)
...

That also looks a lot like we have plain-text passwords, and you know that's really REALLY bad, right? So bad we don't even do it for practice/learning projects.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794