2 Problems - Pulling Records and Displaying Results in ComboBox - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

2 Problems - Pulling Records and Displaying Results in ComboBox

chip050555chip050555 Posts: 32Member
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.

[code]
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()
[red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """[/red]
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
[/code]

Comments

  • digitalgeekdigitalgeek Posts: 59Member
    [code]

    [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """[/red]
    [/code]

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

    [code]

    [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "[/red][blue]"[/blue] [red]& txtWorkOrder.Text[/red] [blue]& """[/blue]
    [/code]

    new line...

    [code]

    [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = " & txtWorkOrder.Text[/red]
    [/code]

  • chip050555chip050555 Posts: 32Member
    : [code]
    :
    : [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "" & txtWorkOrder.Text & """[/red]
    : [/code]
    :
    : this first thing I would try is to remove youe extra quotes from this line...
    :
    : [code]
    :
    : [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = "[/red][blue]"[/blue] [red]& txtWorkOrder.Text[/red] [blue]& """[/blue]
    : [/code]
    :
    : new line...
    :
    : [code]
    :
    : [red]DbSQL = "SELECT * FROM tblqty WHERE WorkOrder = " & txtWorkOrder.Text[/red]
    : [/code]
    :
    :
    I tried to remove the quotes along with other suggestions and now I get an Exception error
    [code]
    Private DbSQl As String = "SELECT workorder, qty, topassy, subassy1, subassy2, datestamp FROM tblQty WHERE WorkOrder = '" & txtWorkOrder.Text & "'"
    [/code]

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

    Additional information: Object reference not set to an instance of an object.[/blue]

  • digitalgeekdigitalgeek Posts: 59Member
    [b][red]This message was edited by digitalgeek at 2005-9-21 1:17:53[/red][/b][hr]
    [b][red]This message was edited by digitalgeek at 2005-9-20 18:15:3[/red][/b][hr]
    try this change to the SQL commands...

    [code]
    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")
    [red] 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[/red]
    Try

    tblData.Fill(ds)

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



    [/code]

    when you reference the table you can reference it as:

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



Sign In or Register to comment.