September 11, 2002 at 2:40 pm
I am creating a database documentor. I am getting an error message (below) on the code below and need some help. I am using C#.Net to create the program. Any feedback would be great.
Error message:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in DBDocumentor.exe
Additional information: [SQL-DMO]The ID '5' was not found in the Tables collection.
Code:
for (int i = 1; i <= this.poSqlDMO.Databases.ItemByID(DatabaseNumber).Tables.Count-1; i++)
{
this.lstTables.Items.Add (this.poSqlDMO.Databases.ItemByID(DatabaseNumber).Tables.ItemByID(i).Name);
}
Thanks
Jim
Thanks
Jim
September 11, 2002 at 3:37 pm
Think your counter must be off. Tried using for/each?
Andy
September 11, 2002 at 3:56 pm
Thanks for the feedback. I am new to the whole for each loop thing. would I use the code below?
foreach (this.poSqlDMO.Databases.ItemByID(DatabaseNumber).Tables in this.poSqlDMO.Databases)
{
this.lstTables.Items.Add (this.poSqlDMO.Databases.ItemByID(DatabaseNumber).Tables.ItemByID(i).Name);
}
Thanks
Jim
Thanks
Jim
September 11, 2002 at 8:13 pm
Close, but I think you are doing more work than you need. Then again, I read C# about as well as I read Klingon. Here is similar code for VB6.
dim db as database
dim tbl as table
for each db in server.databases
print db.name
for each tbl in db.tables
print tbl.name
next
next
No reason to use the ItemByID method unless you're looking for one specific db.
Andy
September 12, 2002 at 7:38 am
Andy,
The program retrieves the databases and lists them in a list box. When the user clicks on a database the tables for that database are retrieved. Would the code be the following?
dim db as database
dim tbl as table
for each db in server.databases(x)
print db.name
for each tbl in db.tables
print tbl.name
next
next
Thanks
Jim
Thanks
Jim
September 12, 2002 at 11:17 am
Typically I'd do this:
set odb=oserver.databases("Northwind")
for each otbl in odb.tables
etc, etc
next
set odb=nothing
Andy
September 17, 2002 at 9:56 am
Andy,
Would the code below work in VB.Net?
set odb=oserver.databases("Northwind")
Thanks
Jim
Thanks
Jim
September 17, 2002 at 3:52 pm
Nope. Have to do it a bit differently:
odb = oserver.Databases.Item("Pubs")
Andy
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply