Columns are not in any particular order after restore

I have a table with 38 columns in it.  The order of the columns is very important, for in my C# program I use an enumeration of the column name to address the particular column.

After adding two columns, they were not placed at the end of the table, where I thought they would be.  Instead, they were placed before the last existing column, which throws the enumeration off and I don't get the right data.

For example: In the code below, "Notes" is the enumerator to get to the 25th column.
if (!data.IsDBNull((int)tBooks.Notes))

Open in new window


Questions:  
Why didn't it add the two columns at the end of the table?
how do I determine the order of the columns?
or is there a better way of doing this?
rmmarshAsked:
Who is Participating?
 
rmmarshAuthor Commented:
What about this?  will it ignore the order of the columns?

 
if ((int)dr["Quantity"].ToString().Length == 0)  // if Qty is blank, default is 0

Open in new window

0
 
tigin44Commented:
can the last column be a computed column? If so the computed columns always listed at the very end of the table...
0
 
rmmarshAuthor Commented:
No, none of the columns are "computed"
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
rmmarshAuthor Commented:
I found this, which gives me what I need to know.  However, is there anyway to limit the output to one table (i.e. tBooks)?

 
select f.rdb$relation_name, f.rdb$field_name
from rdb$relation_fields f
join rdb$relations r on f.rdb$relation_name = r.rdb$relation_name
and r.rdb$view_blr is null
and (r.rdb$system_flag is null or r.rdb$system_flag = 0)
order by 1, f.rdb$field_position;

Open in new window

0
 
rmmarshAuthor Commented:
Please ignore the last post... created a new question...
0
 
Nick UpsonPrincipal Operations EngineerCommented:
   Why didn't it add the two columns at the end of the table?

unless the column position is specified in the "alter table ..." firebird puts a new column wherever it wants to

    how do I determine the order of the columns?

you have the sql above

    or is there a better way of doing this?

yes, never depend upon the order of the columns from "select *", the columns will always be in the order you explicitly list them "select col1, col2 ..."
0
 
rmmarshAuthor Commented:
I found this, which is the correct answer.  Works like a champ!
0
 
rmmarshAuthor Commented:
Moderator:  I want to give points to Nick Upson for his answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.