2 Replies - 238 Views - Last Post: 08 August 2018 - 12:23 AM Rate Topic: -----

#1 SteelRoar   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-August 18

coding from VB 2010 "syntax error in insert into statement"

Posted 07 August 2018 - 08:58 PM

Imports System.Data.OleDb

Public Class Form3

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
         If TextBox1.Text = " " Or TextBox2.Text = " " Or TextBox3.Text = " " Then
            MsgBox("Data Program Studi Harus Lengkap. Semua Diinput ")
        Else
            Call KoneksiDB()
            Cmd = New OleDbCommand("select No, Jenis,Keterangan" & _
                                  " from rusaktb where No = " & _
                                   " '" & Trim(TextBox3.Text) & " ' ", conn)
            dr = Cmd.ExecuteReader
            dr.Read()
            If Not dr.HasRows = True Then
                Dim SQLTambah As String = "Insert into rusaktb " & _
                " (No, Jenis,Keterangan) " & _
                " values('" & Trim(TextBox3.Text) & "', " & _
                " '" & Trim(TextBox1.Text) & "',  " & _
                " '" & Trim(TextBox2.Text) & "')"
                Cmd = New OleDbCommand(SQLTambah, conn)
                Cmd.ExecuteNonQuery()
                Call kosongkan_Data()
                Call tampilkan_Data()
            Else
                Dim SQLUpdate As String = "UPDATE  rusaktb SET " & _
                                "  Keterangan        ='" & Trim(TextBox2.Text) & "', " & _
                                "  No     ='" & Trim(TextBox3.Text) & "' " & _
                                "  where Jenis       = '" & Trim(TextBox1.Text) & " '"
                Cmd = New OleDbCommand(SQLUpdate, conn)
                Cmd.ExecuteNonQuery()
                Call kosongkan_Data()
                Call tampilkan_Data()
            End If
        End If
        Call kosongkan_Data()
        Call tampilkan_Data()
        Dim pesan = MessageBox.Show("No : " + " " & Trim(TextBox3.Text) & " " + " sudah ada dan Tersimpan", "Data Ditemukan", _
         MessageBoxButtons.OK, MessageBoxIcon.Question)
    End Sub

    Private Sub kosongkan_Data()
        Throw New NotImplementedException
    End Sub

    Private Sub tampilkan_Data()
        Throw New NotImplementedException
    End Sub

    Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
         'TODO: This line of code loads data into the 'RusakDataSet1.rusaktb' table. You can move, or remove it, as needed.
        Me.RusaktbTableAdapter.Fill(Me.RusakDataSet1.rusaktb)

    End Sub

    Private Sub TextMati()
        Throw New NotImplementedException
    End Sub

    Private Function SQLSimpan() As Object
        Throw New NotImplementedException
    End Function

End Class


:code:

hallo sir , i feel like an idiot when i try to fix this issue and im stuck .pls help me

This post has been edited by modi123_1: 07 August 2018 - 09:31 PM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: coding from VB 2010 "syntax error in insert into statement"

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14690
  • View blog
  • Posts: 58,702
  • Joined: 12-June 08

Re: coding from VB 2010 "syntax error in insert into statement"

Posted 07 August 2018 - 09:33 PM

What is your question?

Use parameters and not string composition.

Better for understanding, better for type conversion, and better for security.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,305
  • Joined: 12-December 12

Re: coding from VB 2010 "syntax error in insert into statement"

Posted 08 August 2018 - 12:23 AM

I agree with modi.

For the moment, though, 'No' is a reserved word in Access - assuming you are using Access. Surround it with square brackets or, preferably, rename the field to something more meaningful.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1