Member Avatar for සශික

I just use this code to input data to oracle database from vb.net.

Try
            Dim mstream As New System.IO.MemoryStream()
            PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim arrImage() As Byte = mstream.GetBuffer()
            mstream.Close()

            query = "INSERT INTO ds.students (ID,NAME,PIC)" & _
           "VALUES (@ID,@NAME,@PIC);"
            Dim cmd As OracleCommand = New OracleCommand(query, con)
            cmd.Parameters.Add("@ID", Convert.ToInt32(TextBox1.Text))
            cmd.Parameters.Add("@NAME", Convert.ToString(TextBox2.Text))
            cmd.Parameters.Add("@PIC", arrImage)
            Try
                con.Open()
                cmd.ExecuteNonQuery()
                TextBox1.Clear()
                TextBox2.Clear()
                MessageBox.Show("Added Successfully !")
                con.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
                Try
                    If (con.State = ConnectionState.Open) Then
                        con.Close()
                    End If
                Catch ex2 As Exception
                    MsgBox(ex2.Message)
                End Try
            End Try
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            con.Close()
        End Try

when I run this code it give error:
"ORA-00936- missing expression"
Please help me

The SQL statement looks fine to me. Maybe the issue is with the byte variable. What is the column type of PIC in the database?

Your SQL statement holds an extra ; Semicolon at its end, which can give you this type of exception.
In Oracle SQL editor or any other Database system like MySQL, MSSQL or PosgreeSQL semicolon should be used to denote as end of statement, but not in vb . Use semicolon in SQL statement in vb it means it has another SQL statement to run after first one. You can use semicolon to delimit multiple sql statement in vb
examp:

query="Select * From Table1; Drop Table Table1"

Hope, it can help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.