Member 12879517 Ответов: 0

Проблема с транзакцией: вы не можете добавить или изменить запись, так как в таблице "TBL_ORDER_LIST_A155960" требуется связанная запись.


я не знаю, в чем проблема. хотя мои данные доступа верны. Помоги мне

Что я уже пробовал:

Public Class frm_makeorder_A155960
    Dim t As Double
    Private Sub Frm_productdetails_A155960_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim current_date As String = Date.Now
        lbl_date.Text = current_date

        refresh_grid()
        refresh_count()
        refresh_staff()
        fill()

        grd_neworder.ColumnCount = grd_order.ColumnCount

        For i = 0 To grd_neworder.ColumnCount - 1
            grd_neworder.Columns(i).HeaderText = grd_order.Columns(i).HeaderText

        Next

        Dim mysql As String = "SELECT FLD_PRODUCT_ID FROM TBL_PRODUCTS_A155960"

        Dim mydatatable As New DataTable

        Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)

        myreader.Fill(mydatatable)

        lst_productid.DataSource = mydatatable
        lst_productid.DisplayMember = "FLD_PRODUCT_ID"

        refrsh_text(lst_productid.Text)
    End Sub
    Private Sub refresh_grid()
        grd_order.DataSource = run_sql_query("SELECT * FROM TBL_ORDER_A155960")

    End Sub

    Private Sub refrsh_text(ByVal productid As String)
        Dim mysql As String = " SELECT * FROM TBL_PRODUCTS_A155960 WHERE FLD_PRODUCT_ID = '" & productid & "'"

        Dim mydatatable As New DataTable

        Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)

        myreader.Fill(mydatatable)

        txt_productid.Text = mydatatable.Rows(0).Item("FLD_PRODUCT_ID")
        txt_productname.Text = mydatatable.Rows(0).Item("FLD_PRODUCT_NAME")
        txt_price.Text = mydatatable.Rows(0).Item("FLD_PRICE")
        txt_category.Text = mydatatable.Rows(0).Item("FLD_CATEGORY")
        txt_weight.Text = mydatatable.Rows(0).Item("FLD_PRODUCT_NAME")
        txt_country.Text = mydatatable.Rows(0).Item("FLD_COUNTRY")
        txt_description.Text = mydatatable.Rows(0).Item("FLD_DESCRIPTION")

        Try
            pic_productid.BackgroundImage = Image.FromFile("pictures/" & txt_productid.Text & ".jpg")

        Catch ex As Exception
            pic_productid.BackgroundImage = Image.FromFile("pictures/nophoto.jpg")

        End Try


    End Sub

    Private Sub lst_productid_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lst_productid.MouseClick

        refrsh_text(lst_productid.Text)

    End Sub
   Private Sub refresh_count()

        Dim count As Integer = 1
        Dim mysql As String = "SELECT COUNT (FLD_ORDER_ID) As count_id FROM TBL_ORDER_A155960"
        Dim mydatatable As New DataTable
        Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)
        myreader.Fill(mydatatable)
        count += mydatatable.Rows(0).Item("count_id")
        TextBox8.Text = "D" + count.ToString("000")

    End Sub
    Private Sub refresh_staff()

        Dim mysql As String = "SELECT FLD_STAFF_ID FROM TBL_STAFF_A155960"
        Dim mydatatable As New DataTable
        Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)
        myreader.Fill(mydatatable)
        ComboBox1.DataSource = mydatatable
        ComboBox1.DisplayMember = "FLD_STAFF_ID"

    End Sub
    Private Sub fill()

        Dim mysql As String = "SELECT * FROM TBL_CUSTOMER_A155960"
        Dim mydatatable As New DataTable
        Dim myreader As New OleDb.OleDbDataAdapter(mysql, myconnection)
        myreader.Fill(mydatatable)

        cmb_cust.DataSource = mydatatable
        cmb_cust.DisplayMember = "FLD_CUSTOMER_ID"

    End Sub
 
    Private Sub refresh_price()

        If grd_neworder.RowCount > 1 Then
            t = 0
            For index As Integer = 0 To grd_neworder.RowCount - 1
                t += Convert.ToDouble(grd_neworder.Rows(index).Cells(3).Value)
            Next
            TextBox4.Text = "RM " & t
        ElseIf grd_neworder.RowCount = 1 Then
            TextBox4.Text = "RM " & Convert.ToDouble(grd_neworder.Rows(0).Cells(3).Value) & ""
        End If

    End Sub
    Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click

        'refresh_count()
        ' c = c + 1
        Dim mytransaction As OleDb.OleDbTransaction
        myconnection2.Open()
        mytransaction = myconnection2.BeginTransaction
        Try

            Dim mysql As String = "INSERT INTO TBL_ORDER_A155960 (FLD_ORDER_ID,FLD_STAFF_ID,FLD_CUSTOMER_ID) values (""" &
            TextBox8.Text & """,""" & ComboBox1.Text & """,""" & cmb_cust.Text & """)"

            Dim mywriter As New OleDb.OleDbCommand(mysql, myconnection2,
            mytransaction)

            mywriter.ExecuteNonQuery()
            ' Next
            mytransaction.Commit()
            myconnection2.Close()
            Beep()
            MsgBox("You can make new order now!")
            refresh_grid()
            grd_neworder.Rows.Clear()
        Catch ex As Exception
            Beep()
            MsgBox("Problem with transaction:" & vbCrLf & vbCrLf & ex.Message)
            mytransaction.Rollback()
            myconnection2.Close()
            refresh_grid()
        End Try

    End Sub
    Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
        grd_neworder.RowCount = grd_neworder.RowCount + 1
        refrsh_text(lst_productid.Text)
    End Sub

0 Ответов