Results 1 to 6 of 6

Thread: General program help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    General program help

    I have a program, for an opticians...

    I need to make 4 working screens.. I can order spectacles, this works...

    I choose a customer from CustomerTable
    Adds a record to a SpecSalesTable, and an auto key is allocated to each sale. (SpecSalesID)


    In another screen, I need to display all the frames which have been ordered.
    These frames are in the FrameID - SpecSalesTable

    When I click the frameID in the listbox, I need the SpecSalesID to be loaded corrosponding to the frameID... which is in a different table, so Inner join is used, but none of mine will work at the moment...

    Some code:
    RARRR Code:
    1. Dim ConnectionString As String
    2.         Dim SQLString As String
    3.         Dim cmd As System.Data.OleDb.OleDbCommand
    4.         Dim conn As System.Data.OleDb.OleDbConnection
    5.         Dim dr As System.Data.OleDb.OleDbDataReader
    6.         ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data "
    7.         ConnectionString += "Source=" & "Opticians.accdb "
    8.         conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
    9.         TextBox1.Text = FramesListBox.Text
    10.         SQLString = "SELECT * FROM SpecSalesTable "
    11.         SQLString += "INNER JOIN CustomerTable ON SpecSalesTable.CustomerID = CustomerTable.CustomerID "
    12.         SQLString += "Where '" & TextBox1.Text & "'"
    13.         SQLString += "= SpecSalesTable.FrameID"
    14.  
    15.         'frame id = stock id
    16.         ' spec sales table
    17.         ' stock table
    18.         Try
    19.             conn.Open()
    20.             If ConnectionState.Open.ToString = "Open" Then
    21.                 cmd = New System.Data.OleDb.OleDbCommand(SQLString, conn)
    22.                 dr = cmd.ExecuteReader()
    23.                 If dr.HasRows Then
    24.                     dr.Read()
    25.                     If Not IsDBNull(dr.Item("FrameID")) Then
    26.                         TextBox1.Text = dr.Item("FrameID").ToString
    27.                     End If
    28.                     If Not IsDBNull(dr.Item("CustomerID")) Then
    29.                         TextBox2.Text = dr.Item("CustomerID").ToString
    30.                     End If
    31.                     If Not IsDBNull(dr.Item("Surname")) Then
    32.                         TextBox3.Text = dr.Item("Surname").ToString
    33.                     End If
    34.                     If Not IsDBNull(dr.Item("Firstname")) Then
    35.                         TextBox3.Text = dr.Item("Firstname").ToString
    36.                     End If
    37.  
    38.                 End If
    39.             End If
    40.         Catch ex As Exception
    41.         End Try

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: General program help

    Code:
    TextBox1.Text = FramesListBox.SelectedItem.ToString
    But I don't really see any reason why using TextBox1 at all. This can be accomplished simply by:
    Code:
    SQLString = "SELECT * FROM SpecSalesTable "
    SQLString += "INNER JOIN CustomerTable ON SpecSalesTable.CustomerID = CustomerTable.CustomerID "
    SQLString += "Where '" & FramesListBox.SelectedItem.ToString & "'"
    SQLString += "= SpecSalesTable.FrameID"
    You only need to check whether your FramesListBox really has some selected item (check whether its .SelectedIndex <> -1)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: General program help

    Thanks for the reply... doesn't seem to do anything... (not putting data into the textboxes...)

  4. #4
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: General program help

    I suspect that your SQL query does not return anything. use this code before Try:

    Code:
    Debug.WriteLine(SQLString)
    Does your SQLString appears what it should be?

    You have to select something in the FramesListBox, by the way.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Location
    Ireland
    Posts
    85

    Re: General program help

    Whereabouts should I put the debug thing in...

    Yeah I'm selecting the items Sorry about the noob questions :P lol

  6. #6

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width