Как мне сделать форму для вставки
Когда я запускаю программу, данные отображаются не в правильном порядке. Кто-нибудь может сказать мне, почему это произошло? И когда я пытаюсь вставить данные, он говорит, что
-В данных, которые вы ввели, есть ошибка, как показано ниже. Синтаксическая ошибка в операторе INSERT INTO."
Что я уже пробовал:
Public Class frm_insertproduct_A155751 Dim defaultpicture As String = Application.StartupPath & "\pictures\NoImage.jpg" Private Sub frm_insertproduct_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load refresh_grid() grd_product.DataSource = run_sql_query("SELECT * FROM TBL_PRODUCT_A155751") txt_productid.Text = generate_productid() txt_picture.Text = defaultpicture pic_product.BackgroundImage = Image.FromFile(defaultpicture) End Sub Private Function generate_productid() As String Dim lastproductid As String = run_sql_query("SELECT MAX(FLD_PRODUCT_ID) AS LASTPRODUCTID FROM TBL_PRODUCT_A155751").Rows(0).Item("LASTPRODUCTID") MsgBox(lastproductid) Dim newproductid As String = "P" & Mid(lastproductid, 2) + 1 Return newproductid End Function Private Sub refresh_grid() Dim mysql As String = "SELECT * FROM TBL_PRODUCT_A155751" Dim mydatatable As New DataTable Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection) myreader.Fill(mydatatable) grd_product.DataSource = mydatatable End Sub Private Sub clear_fields() txt_productid.Text = "" txt_productname.Text = "" txt_productprice.Text = "" txt_productbrand.Text = "" txt_producttype.Text = "" txt_productcategory.Text = "" txt_productquality.Text = "" End Sub Private Sub btn_addproduct_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addproduct.Click Dim mysql As String = "INSERT INTO TBL_PRODUCT_A155751 VALUES('" & txt_productid.Text & "', '" & txt_productname.Text & "', '" & txt_productprice.Text & "','" & txt_productbrand.Text & "', '" & txt_producttype.Text & "','" & txt_productcategory.Text & "', '" & txt_productquality.Text & "')" Dim mywriter As New OleDb.OleDbCommand(mysql, myconnection2) Try mywriter.Connection.Open() mywriter.ExecuteNonQuery() mywriter.Connection.Close() My.Computer.FileSystem.CopyFile(txt_picture.Text, "pictures\" & txt_productid.Text & ".jpg") grd_product.DataSource = run_sql_query("SELECT * FROM TBL_PRODUCT_A155751") txt_productid.Text = generate_productid() txt_productname.Text = "" txt_productprice.Text = "" txt_productbrand.Text = "" txt_producttype.Text = "" txt_productcategory.Text = "" txt_productquality.Text = "" pic_product.BackgroundImage = Image.FromFile(defaultpicture) Catch ex As Exception Beep() MsgBox("There is a mistake in the data you entered, as shown below" & vbCrLf & vbCrLf & ex.Message) mywriter.Connection.Close() End Try End Sub Private Sub btn_select_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_picture.Click Dim mydesktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop OpenFileDialog1.InitialDirectory = mydesktop OpenFileDialog1.FileName = "" OpenFileDialog1.Filter = "JPG files(*.jpg)|*.jpg" OpenFileDialog1.ShowDialog() pic_product.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName) txt_picture.Text = OpenFileDialog1.FileName End Sub Private Sub btn_back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_back.Click frm_mainmenu_A155751.Show() Me.Dispose() End Sub End Class