Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2004, 08:33 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling code multiple time????

I call the code below on a load event and then later on a timer event, it works fine for the load event and then falls over when it is called for the second time with the debugging dialogbox saying Column 'JobNo' does not belong to table Job. Although it is in the job table, especially if the code has already worked once perfectly. Also if I press continue at the debugging dialogbox, it continues quite happily.

Thanks in advance

Louisa


 'Declaring TAPING Variable
        Dim StrTapingMax As String, TapingMaxAdapter As New OleDb.OleDbDataAdapter
        Dim TapingMaxData As New DataSet, TapingCount As Integer
        Dim StrTap As String, TapData As New DataSet
        Dim TapAdapter As New OleDb.OleDbDataAdapter
        '////

TapData.Clear()
        'Populating the grid
        StrTap = "Select JobNo, TapingEUs, Priority, RALcolour from job where omit = false and station = 'taping' order by priority"
        TapAdapter = New OleDb.OleDbDataAdapter(StrTap, myConnection)
        TapAdapter.Fill(TapData, "Job")

        If TapData.Tables(0).Rows.Count > 0 Then
            MyFrmLeft.GridTaping.DataSource = TapData
            MyFrmLeft.GridTaping.DataMember = "Job"
        End If

        TapAdapter.Dispose()
        TapAdapter = Nothing
        TapData.Dispose()
        TapData = Nothing
        MyFrmLeft.GridTaping.Refresh(

 
Old May 11th, 2004, 11:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Louisa,

How do you call this code? Do you have the same code in both events, or have you encapsulated the code in a function or sub which you call from the other events?

Either way, the second solution is better IMO, as it saves you from typing and maintaining the same stuff twice and minimizes the bug chances.

Instead of clearing the TapData you could set it to null, or create a new variable at the method level. I am not sure whether Clear just clears the items or also the schema, but with a new instance you can be sure you're not dealing with any left overs.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 13th, 2004, 04:06 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is called as a refresh page procedure on the load event and scanned procedure when text is entered into a box to change the station values and this updates the database, therefore creating the need to change the data held within the grids. I have tried both methods first I reused the code and now I have tried to encapsulate it, also I took out the clear.

Dim StrTap As String, TapData As New DataTable
'TAPING
        'Populating the grid
        StrTap = "Select JobNo, TapingEUs, Priority, RALcolour from job where omit = false and station = 'taping' order by priority"
        TapData = GetDataTable(StrTap)

        If TapData.Rows.Count > 0 Then
            MyFrmLeft.GridTaping.DataSource = TapData
        End If


Private Function GetDataTable(ByVal Sql As String) As DataTable

        SyncLock myConnection
            Dim da As New OleDb.OleDbDataAdapter(Sql, myConnection)
            Dim dt As New DataTable

            da.Fill(dt)

            Return dt

        End SyncLock

End Function

It is still giving a very similar error message

Column 'JobNo' does not belong to table

It is falling over on this line, does this mean it is actually my grid that has a problem rather that my datatable?

MyFrmLeft.GridTaping.DataSource = TapData

Thanks for your help

Louisa
 
Old May 13th, 2004, 05:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not sure; I think that depends on the grid. Usually, I have no problems binding different dataset to the same grid. The old columns structure is overwritten with the new ones from the DataSet.

I am still a bit unclear how you're calling things. Try to set up things like this:

Private Sub Form_Load()
  ' Do LoadStuff here

  ' When you're done, call your GridRefreshMethod
  GridRefresh()
End Sub

Private Sub OnTextEntered()
  ' Handle entered text here

  ' When you're done, call your GridRefreshMethod
  GridRefresh()
End Sub

Private Sub GridRefresh()
  ' Go into the database, get new data
  ' and bind to grid
End Sub


With this pseudo code, both events (Form_Load and OnTextEntered) do their own thing and then call a common procedure that updates the grid. This way, you can be sure both do the same thing.

Not sure if it helps, but it may get you closer to the final solution.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 13th, 2004, 05:22 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have been playing (as I am a little desperate) and have changed the string to "Select * from Job" and it is still coming up with the same message Column 'JobNo' does not belong to table

I am very confused now

Louisa

 
Old May 13th, 2004, 05:31 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, since you include that column in your SELECT statement, I am sure that is not the problem.

Where exactly do you get this error? Who throws it and when? When you step / debug through your code, how does your DataTabe look like in the watch window? And how does the grid look? Does the DataTable contain the data and columns you expect?

If you debug your code, and examine the important objects, it should be much clearer what is going on.....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 13th, 2004, 08:02 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The error is on this line

MyFrmLeft.GridTaping.DataSource = TapData

when the refresh grid is called from the text changed event. I have debugged/stepped though my code and had a look at the datatable and grid via the watch window and immediate windows and the datatable etc contains the correct information. Also when I press continue when the error dialog box comes up the grid refreshes correctly and contains all the correct infomation. This is what I can't understand why it falls over if it will coninue perfectly once I pressed the continue button.

Louisa

 
Old May 13th, 2004, 09:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am out of ideas. They way you described your application, this shouldn't happen. I am sure something is going wrong that we're all overlooking, but it's hard to tell without actually seeing the application at work, stepping through the code.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Blame by KoRn (Track 3 from the album: Untouchables) What's This?
 
Old May 13th, 2004, 10:01 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help, it is very odd, especially as I have found it only happens some of the time not all of the time.

 
Old May 13th, 2004, 10:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You want me to take another close look? If so, you can send me the source again.

If you do, can you strip away even more than the last time? I was a bit confused by all the controls so it was hard for me to see what the app was supposed to do.....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Voice Of The Voiceless by Rage Against The Machine (Track 9 from the album: The Battle Of Los Angeles) What's This?





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling javascript as well as codebehind code k.manisha C# 1 November 27th, 2006 08:47 AM
calling javascript as well as codebehind code k.manisha ASP.NET 1.0 and 1.1 Professional 1 November 25th, 2006 01:19 PM
calling javascript as well as codebehind code k.manisha ASP.NET 1.x and 2.0 Application Design 0 November 24th, 2006 04:28 AM
Calling a DLL from the sql code mtrein SQL Language 1 February 12th, 2005 02:10 AM
Multiple queries at one time VBAHole22 SQL Server 2000 2 July 27th, 2003 06:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.