I don't know what's wrong with my code, when I add data then save, I get this error.
FYI I use Visual Basic language.
[1][This is the error of my code]
[1][https://i.stack.imgur.com/sxSie.png]
Private Sub TsSave_Click(sender As Object, e As EventArgs) Handles TsSave.Click
If aksi = "insert" Then
TBL_BukuTableAdapter.InsertQuery(txtJudulBuku.Text, txtPengarang.Text, txtPenerbit.Text, txtTahunTerbit.Text, txtkategori.Text)
TsRefresh.Text = "Refresh"
Else
TBL_BukuTableAdapter.UpdateQuery(txtJudulBuku.Text, txtPengarang.Text, txtPenerbit.Text, txtTahunTerbit.Text, txtkategori.Text, txtIdbuku.Text)
End If
Me.TBL_BukuTableAdapter.Fill(Me.UASDataSet.TBL_Buku)
TsAdd.Enabled = True
TsDelete.Enabled = True
TsSearch.Enabled = True
aksi = "update"
End Sub
This is my full code
Public Class Form1
Dim aksi As String = "update"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'UASDataSet.TBL_Buku' table. You can move, or remove it, as needed.
Me.TBL_BukuTableAdapter.Fill(Me.UASDataSet.TBL_Buku)
txtIdbuku.ReadOnly = True
End Sub
Private Sub TsAdd_Click(sender As Object, e As EventArgs) Handles TsAdd.Click
TsAdd.Enabled = False
TsDelete.Enabled = False
TsSearch.Enabled = False
TsRefresh.Text = "Cancel"
aksi = "insert"
TBLBukuBindingSource.AddNew()
txtIdbuku.Text = TBL_BukuTableAdapter.IdBukuBaru()
txtJudulBuku.Focus()
End Sub
Private Sub TsSave_Click(sender As Object, e As EventArgs) Handles TsSave.Click
If aksi = "insert" Then
TBL_BukuTableAdapter.InsertQuery(txtJudulBuku.Text, txtPengarang.Text, txtPenerbit.Text, txtTahunTerbit.Text, txtkategori.Text)
TsRefresh.Text = "Refresh"
Else
TBL_BukuTableAdapter.UpdateQuery(txtJudulBuku.Text, txtPengarang.Text, txtPenerbit.Text, txtTahunTerbit.Text, txtkategori.Text, txtIdbuku.Text)
End If
Me.TBL_BukuTableAdapter.Fill(Me.UASDataSet.TBL_Buku)
TsAdd.Enabled = True
TsDelete.Enabled = True
TsSearch.Enabled = True
aksi = "update"
End Sub
Private Sub TsDelete_Click(sender As Object, e As EventArgs) Handles TsDelete.Click
If MessageBox.Show("Delete Data?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
TBL_BukuTableAdapter.DeleteQuery(txtIdbuku.Text)
Me.TBL_BukuTableAdapter.Fill(Me.UASDataSet.TBL_Buku)
End If
End Sub
Private Sub TsRefresh_Click(sender As Object, e As EventArgs) Handles TsRefresh.Click
TsRefresh.Text = "Refresh"
Me.TBL_BukuTableAdapter.Fill(Me.UASDataSet.TBL_Buku)
End Sub
Private Sub TsSearch_Click(sender As Object, e As EventArgs) Handles TsSearch.Click
If TxtKeyword.Text <> "" Then
TBL_BukuTableAdapter.FillByJudulBuku(UASDataSet.TBL_Buku, TxtKeyword.Text)
End If
End Sub
End Class
Edit: I just add the Id_buku
to this code.
But it still don't work
[this is the code][2]
[2][https://i.stack.imgur.com/i3RRQ.png]
If aksi = "insert" Then TBL_BukuTableAdapter.InsertQuery(txtid_buku.text,txtJudulBuku.Text, txtPengarang.Text, txtPenerbit.Text, txtTahunTerbit.Text, txtkategori.Text)
question from:
https://stackoverflow.com/questions/65849126/system-data-sqlclient-sqlexception-incorrect-syntax-near-on-button-save