Results 1 to 5 of 5

Thread: Database program

  1. #1
    SLG29 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    May 2005
    Posts
    13
    Reputation
    100

    Database program

    Database program

    Got a problem with a database application

    I'm trying to display information from a database into a listbox and 5 textboxes these are as follows

    ListBox Customer ID
    TextBox1 First Name
    TextBox2 Last Name
    TextBox3 City
    TextBox4 State
    TextBox5 Zip Code

    The listbox allows selection of a customerid which then displays the details of that customer id into the 5 read only textboxes

    There is a also a datagrid which lists all the order details for the customer these fields are OrderID OrderPrice and CustomerID

    This is what I have so far

    Code:
     
    Imports System.Data.OleDb

    Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim dr As OleDbDataReader
    Dim cnShop As OleDbConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    cnShop = New OleDbConnection
    cnShop.ConnectionString = _
    "Data Source=C The Doughnut Shop.mdb;Provider=Microsoft.Jet.OLEDB.4.0;"
    End Sub
    End Class

    Any tips/guidance would be great

  2. #2
    Blokz is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jul 2005
    Location
    Jacksonville, Florida
    Posts
    55
    Reputation
    98
    What problem are you having?

  3. #3
    SLG29 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    May 2005
    Posts
    13
    Reputation
    100
    At the moment I can't seem to load the required info into the listbox and the textboxes



    The data handling has to be done via a new class which is as follows

    Customer ID (Read/Write)
    First Name (Read Only)
    Last Name (Read Only)
    City (Read Only)
    State (Read Only)
    Zip Code (Read Only)

    Methods

    GetOrders (Returns a dataview of all orders for current customer ID)
    GetOrderDetails (Returns a data view of the order items for a given order ID)

    There is a second part to the program but I'm trying to sort this out first

    If you need any more info please let me know

    Thanks

  4. #4
    nakracreative is offline VB.NET Forum Enthusiast
    .NET Framework
    Join Date
    Aug 2005
    Location
    India
    Posts
    72
    Reputation
    98

    displaying details from a database

    you have a listbox control and on the basis of selection of listbox value i.e. customerid the corresponding values will be shown in the textboxes.

    here goes the code:

    first you have to fill the listbox with the customerid's

    dim objconnection as new sqlclient.sqlconnection("<connection string>")

    dim objcommand as new sqlclient.sqlcommand("select * from tablename")
    objcommand.connection=objconnection

    objcommand.connection.open
    dim objreader as system.data.idatareader=objcommand.executereader(c onnection.close)

    while objreader.read
    listbox1.items.add(objreader("customer_id"))
    wend


    this above mentioned code will populate your listbox control with the values saved in the customer_id field of your table.

    now add the following code for the population of textboxes supposing that the dataset has already been populated

    eventhandler : listbox1_selectionchanged()

    dim objdataview as new dataview(objdataset.tables("<tablename>")
    objdataview.sort="customer_id"

    dim inum as integer
    inum=objdataview.find(listbox1.value)

    textbox1.text=objdataset.tables(<tablename>).row(i num).item(0)
    '
    '
    '
    '
    textboxn.text=objdataset.tables(<tablename>).row(i num).item(n)

    i hope it serves the needful

  5. #5
    SLG29 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    May 2005
    Posts
    13
    Reputation
    100
    Thanks for the reply

    Tried that but still getting errors, I think I need to include the classes and methods mentioned to do the data handling

    Any ideas

    Thanks for your help

Bookmarks

Posting Permissions

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