linabeb 0 Light Poster

hi im back with the new problem and the same problem..huhuh

first is the same problem which is why does the data is not being inserted to the db..below is my full code for the custhome page

'Imports WindowsApplication1.LoginForm1
Imports System.Data.OleDb
Imports System.Text.RegularExpressions

Public Class Custhome
    Private _OrderID As Int32 = 0
    Public Property OrderID() As Int32
        Get
            Return _OrderID
        End Get

        Set(ByVal value As Int32)
            _OrderID = value
            RetrieveContactDetails()
        End Set
    End Property
    Private Sub RetrieveContactDetails()

        Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=D:\fnal projek\khurasan.mdb; Persist Security Info = false;")
        Dim cmd As New OleDbCommand("Select Purpose, KQuantity, DQuantity, BQuantity, MeatPerKG, MeatPerGoat from Order Where OrderID = " & _OrderID, conn)

        conn.Open()

        Dim contactReader As OleDbDataReader = cmd.ExecuteReader
        contactReader.Read()
        cmboxpurpose.Text = contactReader("Purpose").ToString
        cmboxkid.Text = contactReader("KQuantity").ToString
        cmboxdoe.Text = contactReader("DQuantity").ToString
        cmboxbuck.Text = contactReader("BQuantity").ToString
        cmboxkg.Text = contactReader("MeatPerKG").ToString
        cmboxgoat.Text = contactReader("MeatPerGoat").ToString


        conn.Close()
    End Sub
    Private Sub Custhome_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        ' LoginForm1.UsernameTextBox.Text = Me.unlbl.Text




        Me.ToolStripStatusLabel1.Text = Date.Now
        ToolStripStatusLabel5.Text = "KHURASAN ONLINE"
        DisplayUser()

    End Sub
    Public Sub DisplayUser()
        Dim currentUser As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
        userIdentityLabel.Text = currentUser.Name
    End Sub

    Public Sub TestProgressBar()
        ' Do a loop to simulate a lengthy task and make the progress bar
        ' show progress to its maximum value.
        While (ToolStripProgressBar1.Value < ToolStripProgressBar1.Maximum)
            System.Threading.Thread.Sleep(10)
            ToolStripProgressBar1.Value += 1
        End While

        ' Reset the progress bar.
        ToolStripProgressBar1.Value = ToolStripProgressBar1.Minimum

    End Sub


    Private Sub savebtn_Click(sender As System.Object, e As System.EventArgs) Handles savebtn.Click
        Dim conn As New OleDbConnection("provider=microsoft.jet.OleDB.4.0;Data Source=D:\fnal projek\khurasan.mdb; Persist Security Info = false;")
        Dim sql As String = String.Empty
        TestProgressBar()



        If _OrderID = 0 Then
            sql = "INSERT INTO Order ([Purpose], [KQuantity], [DQuantity], [BQuantity], [MeatPerKG], [MeatPerGoat]) VALUES ('" & cmboxpurpose.Text & "', '" & cmboxkid.Text & "','" & cmboxdoe.Text & "','" & cmboxbuck.Text & "','" & cmboxkg.Text & "', '" & cmboxgoat.Text & "' ) "
        Else
            sql = "UPDATE Order Purpose = '" & cmboxpurpose.Text & "', KQuantity = '" & cmboxkid.Text & "', DQuantity = '" & cmboxdoe.Text & "', BQuantity = '" & cmboxbuck.Text & "', MeatPerKG = '" & cmboxkg.Text & "', MeatPerGoat = '" & cmboxgoat.Text & "' Where OrderID =" & _OrderID


        End If

        TestProgressBar()


        Try
            conn.Open()

            Dim Command As New OleDbCommand(sql, conn)
            Command.ExecuteNonQuery()
            conn.Close()
            TestProgressBar()

            MsgBox("Success !!!", MsgBoxStyle.Information, "Khurasan Online")

        Catch ex As Exception

            MsgBox(ex.ToString & vbCrLf & sql)

            MsgBox("Incomplete,please insert your order once again !!!", MsgBoxStyle.Exclamation, "Khurasan Online")

        End Try

    End Sub

    Private Sub chckbxkid_CheckedChanged(sender As System.Object, e As System.EventArgs)

    End Sub

    Private Sub TabPage1_Click(sender As System.Object, e As System.EventArgs) Handles TabPage1.Click

    End Sub
End Class

my second problem is.... i want to show the username which has been logged to this sytem..
for example...i have 2 form..first is the login form and 2nd let it be the order form

i want the user to login then only it will be navigate to the 2nd form..and i want the username to be appear in the 2nd form..i have been searching 4 everywhere about it..would u plz help me...

n by the way..i would like to ask... i'm using a tabpage for the customer to choose their order..it's that okay if im using only one save button outside the tab page?? or i must not use the tab page...please2 help me...huhuhuhuh....
oh i forget...im using vb 2010 and ms access... below is my error...and the line is refer to 89.... based on the above post...

Dani AI

Generated

Quick summary for : the username from your login form is easiest to pass into the second form explicitly (property, constructor, or a small session Module). The DB insert/update problem is most likely a SQL or reader issue (Access reserves the word Order, your UPDATE needs a SET clause, and you must check that a DataReader actually returned a row). Using one Save button outside a TabControl is fine — just collect the values from the active tab (or from all tabs) before saving.

Passing the username (three simple patterns)

' Property on the second form
Public Property LoggedUser As String
    Set(value As String)
        lblUser.Text = value
    End Set
End Property

' In Login form (after successful login):
Dim f As New Custhome()
f.LoggedUser = txtUsername.Text
f.Show()
Me.Hide()
' Constructor pattern
Public Sub New(username As String)
    InitializeComponent()
    lblUser.Text = username
End Sub
' In Login:
Dim f As New Custhome(txtUsername.Text)
f.Show()
' Module (global) pattern
Module Session
    Public CurrentUser As String
End Module
' Set Session.CurrentUser = txtUsername.Text in login, read it in Custhome.

Database and retrieval tips

  • Don’t name tables with reserved words (wrap names in square brackets like [Order] or rename the table). See Access reserved words and symbols.
  • Use parameterized queries and Using blocks to avoid SQL syntax mistakes and resource leaks. Example (insert):
Using cn As New OleDbConnection(connStr)
    Using cmd As New OleDbCommand("INSERT INTO [Order] ([Purpose],[KQuantity]) VALUES (?,?)", cn)
        cmd.Parameters.AddWithValue("?", cmbPurpose.Text)
        cmd.Parameters.AddWithValue("?", Integer.Parse(cmbKid.Text))
        cn.Open()
        cmd.ExecuteNonQuery()
    End Using
End Using
  • For UPDATE use UPDATE [Order] SET Field = ? WHERE OrderID = ?.
  • When reading, check If reader.Read() Then ... before accessing fields to avoid exceptions.
  • Check the .mdb path and file permissions (the app must be able to write the file).

Quick checklist: wrap DB calls in Try/Catch, use parameters (no string concatenation), validate reader.Read(), and pass the login username explicitly to the second form.

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.