Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a Pause method or a Wait command in VB.net 2

Status
Not open for further replies.

JoaquimM

Programmer
May 19, 2003
9
US
Hi
Anyone know how to make my program stop executing for a couple of seconds. I make my program open an Access file that automatically runs a query when opened and I want my program to pause to give the query time to run before trying to access a table in the file.
 
My program has no problem opening the Access file, my problem is when I try to open one of the tables in the file I get an error that looks like this

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in test.exe

Additional information: Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

I don't get that error when I try to open another table in the same file though. any ideas what I could do to fix this.
 
Can you post the code you're using to access the database? I have an idea, but I'm not exactly sure how you're getting your data yet.
 
m_cnADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=c:\projects\EASTERN SHORE\database\Sample.mdb")

m_rstContacts.Open("Output", m_cnADOConnection, _
ADODB.CursorTypeEnum.adOpenDynamic, _
ADODB.LockTypeEnum.adLockOptimistic)

Error occurs when second Open statement is called, if I change "Output" to another table in my file program runs fine.

Output is populated by a query that runs when the file is opened.
 
Wow, you're doing this the hardest way possible... in .NET, there are objects you can set up for each of these things that make life *SO* much easier!

Is there any particular reason you have to use ADO instead of ADO.NET?
 
No I'm new to VB so don't know all its capabilities.
What would be an easier way to doing this?
 
First, go to your form's design screen and open up the "Data" section on the toolbar. Select OleDbConnection and add one to your form. This object will contain the connection string for the database. Just set the ConnectionString property using the wizard you'll find in the drop-down box.

Next, go back to the toolbar and add an OleDbDataAdapter object. This is the connection between the database object and your program. Although there is a lot of functionality within this device, I've only used one part... to create Select queries. Go under the "SelectCommand" property, to "Connection"... and choose your OleDbConnection object from the list. Now you can put your SQL statement in

[YourAdapterObject].SelectCommand.CommandText = "SQL Statement Here"

Now... in your code, you do something like this:
Code:
Dim NewTable as New Data.DataTable()
Adapter.SelectCommand.CommandText = "SELECT ..."
Adapter.Fill(NewTable)
This fills "NewTable" with the results of the query. You can access it like this:

Code:
x = NewTable.Rows(n)("Fieldname here")

You may want to peruse the IntelliSense list of objects and properties for each of these data objects... they're pretty powerful... plus, they only open the database when you call for them, so you don't have to worry about closing things up! As for the query that runs when you open the database: what kind of query is it? I'm guessing it's a Make-Table. If so, you could load it into a DataTable object (as I showed above) and access the data from there. All these objects flying around look kinda scary at first... but trust me... if you work with them a while, you'll grow to love them so much more than the old ADO recordsets! If you have any questions, I'll be here for about 4 more hours.

Good Luck!
Ben
 
thanks ben
I have to step away from this for a bit and do some other work but thanks for the help and if i have any more questions I'll post it here. thanks jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top