VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
2 Problems - Pulling Records and Displaying Results in ComboBox Posted by chip050555 on 13 Sept 2005 at 6:20 AM
I am trying to look up and fill a datatable based on a parameter in a textbox. The code looks right however when I execute it does not find any records and goes to my trap to add new records. Additionally, since there may be several rows of data associated with each "workorder" I need to display the infomation in combo boxes. I can fill the combobox with the first record, but how do I fill it with each occurance. This program will be made into an executable file and placed an numerous machines for use.

Private Sub btnLook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLook.Click
        Dim DT As New DataTable()
        'Dim x As Exception
        Dim DbCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = Q:\Kit.mdb")
        Dim DbCmd As New OleDbCommand()
        Dim DbSQL As String
        Dim i As Integer
        DbCon.Open()
        DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """
        Dim tblData As New OleDbDataAdapter(DbSQL, DbCon)
        g_tblData = tblData
        Try
            DT.Clear()
            tblData.Fill(DT)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        g_DT = DT
        Dim DTcmd As New OleDbCommandBuilder(tblData)
        Dim Found As Boolean = False
        For i = 0 To (DT.Rows.Count - 1)
            If DT.Rows(i)("WorkOrder").Equals(Convert.ToString(txtWorkOrder.Text)) Then
                Found = True
                txtQty.Text = Convert.ToString(DT.Rows(i)("Qty"))
                cmbTopAssy.DataSource = DT
                cmbTopAssy.DisplayMember.Equals("topassy")
                cmbTopAssy.Text = Convert.ToString(DT.Rows(i)("topassy"))
                txtTopAssy.Text = Convert.ToString(DT.Rows(i)("topassy"))
                cmbSubAssy1.DataSource = DT
                cmbSubAssy1.DisplayMember.Equals("subassy1")
                cmbSubAssy1.Text = Convert.ToString(DT.Rows(i)("subassy1"))
                txtSubAssy1.Text = Convert.ToString(DT.Rows(i)("subassy1"))
                cmbSubAssy2.DataSource = DT
                cmbSubAssy2.DisplayMember.Equals("subassy2")
                cmbSubAssy2.Text = Convert.ToString(DT.Rows(i)("subassy2"))
                txtSubAssy2.Text = Convert.ToString(DT.Rows(i)("subassy2"))
            End If
            g_i = i
        Next i

        If Found = False Then
            MessageBox.Show("Record not found.  Please add a new record.")
        End If
        DbCon.Close()
    End Sub

Report
Re: 2 Problems - Pulling Records and Displaying Results in ComboBox Posted by digitalgeek on 16 Sept 2005 at 6:26 PM

  DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """     


this first thing I would try is to remove youe extra quotes from this line...


  DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """     


new line...


  DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = " & txtWorkOrder.Text         


Report
Re: 2 Problems - Pulling Records and Displaying Results in ComboBox Posted by chip050555 on 20 Sept 2005 at 10:08 AM
:
: 
:   DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """     
: 

:
: this first thing I would try is to remove youe extra quotes from this line...
:
:
: 
:   DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """     
: 

:
: new line...
:
:
: 
:   DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = " & txtWorkOrder.Text         
: 

:
:
I tried to remove the quotes along with other suggestions and now I get an Exception error
Private DbSQl As String = "SELECT workorder, qty, topassy, subassy1, subassy2, datestamp FROM tblQty WHERE WorkOrder =  '" & txtWorkOrder.Text & "'"


An unhandled exception of type 'System.NullReferenceException' occurred in Kit.exe

Additional information: Object reference not set to an instance of an object.


Report
Re: 2 Problems - Pulling Records and Displaying Results in ComboBox Posted by digitalgeek on 20 Sept 2005 at 6:11 PM
This message was edited by digitalgeek at 2005-9-21 1:17:53

This message was edited by digitalgeek at 2005-9-20 18:15:3

try this change to the SQL commands...

Private Sub btnLook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLook.Click
        Dim ds As new DataSet
        Dim DbCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = Q:\Kit.mdb")
        Dim DbSQL As StringDbSQL = "SELECT * FROM tblqty WHERE WorkOrder = '" & txtWorkOrder.Text & "'"
        Dim DbCmd As New OleDbCommand(DbSQL, DbCon)

        Dim tblData As New OleDbDataAdapter
        tbldata.SelectCommand = DbCmd
        Try

            tblData.Fill(ds)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try





when you reference the table you can reference it as:

ds.tables(0).rows("row no")("field name").tostring()






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.