Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old May 7th, 2008, 03:34 AM
appdeveloper appdeveloper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 34 appdeveloper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 16 m 37 sec
Reputation Power: 2
Adox in vb6

I'm trying to update a database structure from another (updated) database.
When i'm creating the missing fields i can't determine the field properties. I can find what is the name of the missing field, i can determine its type, but for instance if the field is a 'Yes/No' field i'm not able to determine if in the field properties the value 'necessary' is true or false, or if it's index or not, and if it is, what type of index its using. Is there any way to do this (find and set the field properties)?
The code i'm using is this:

Private Sub iniciaTabela(ByVal strNomeTabela As String, ByRef myTable As ADOX.Table, _
ByVal tabelaDestino As ADOX.Table)
Dim intContador As Integer
Dim intIndex As Integer
Dim intInnerIndex As Integer
Dim intIndexColumn As Integer
Dim intInnerIndexColumn As Integer
Dim col As ADOX.Column
Dim bolFound As Boolean
Dim bolIndexFound As Boolean
Dim strErrInfo As String
Dim ADOXindex As New ADOX.Index
Dim intProperties As Integer


On Error GoTo ErrHandler

For Each tabelaDestino In Cat2.Tables
If myTable.Name = tabelaDestino.Name Then

For intContador = 0 To myTable.Columns.Count - 1
bolFound = False
For Each col In tabelaDestino.Columns
If col.Name = myTable.Columns.Item(intContador).Name Then
If col.Type <> myTable.Columns.Item(intContador).Type Then
strErrInfo = "Erro ao tentar actualizar o TIPO de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
col.Type = myTable.Columns.Item(intContador).Type
End If
If col.Attributes <> myTable.Columns.Item(intContador).Attributes Then
strErrInfo = "Erro ao tentar actualizar os atributos de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
col.Attributes = myTable.Columns.Item(intContador).Attributes
End If
If col.DefinedSize <> myTable.Columns.Item(intContador).DefinedSize Then
strErrInfo = "Erro ao tentar actualizar o 'defined size' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
col.DefinedSize = myTable.Columns.Item(intContador).DefinedSize
End If
If col.NumericScale <> myTable.Columns.Item(intContador).NumericScale Then
strErrInfo = "Erro ao tentar actualizar o 'numeric scale' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
col.NumericScale = myTable.Columns.Item(intContador).NumericScale
End If
If col.Precision <> myTable.Columns.Item(intContador).Precision Then
strErrInfo = "Erro ao tentar actualizar a PRECISÃO de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
col.Precision = myTable.Columns.Item(intContador).Precision
End If
If col.RelatedColumn <> myTable.Columns.Item(intContador).RelatedColumn Then
col.RelatedColumn = myTable.Columns.Item(intContador).RelatedColumn
End If
If col.SortOrder <> myTable.Columns.Item(intContador).SortOrder Then
col.SortOrder = myTable.Columns.Item(intContador).SortOrder
End If

bolFound = True
Exit For
End If
Next

If Not bolFound Then
tabelaDestino.Columns.Append myTable.Columns.Item(intContador).Name, myTable.Columns.Item(intContador).Type, myTable.Columns.Item(intContador).DefinedSize


If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Type <> myTable.Columns.Item(intContador).Type Then
strErrInfo = "Erro ao tentar actualizar o TIPO de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Type = myTable.Columns.Item(intContador).Type
End If
If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Attributes <> myTable.Columns.Item(intContador).Attributes Then
strErrInfo = "Erro ao tentar actualizar os ATRIBUTOS de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Attributes = myTable.Columns.Item(intContador).Attributes
End If
If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).DefinedSize <> myTable.Columns.Item(intContador).DefinedSize Then
strErrInfo = "Erro ao tentar actualizar o 'DEFINED SIZE' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).DefinedSize = myTable.Columns.Item(intContador).DefinedSize
End If
If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).NumericScale <> myTable.Columns.Item(intContador).NumericScale Then
strErrInfo = "Erro ao tentar actualizar o 'NUMERIC SCALE' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).NumericScale = myTable.Columns.Item(intContador).NumericScale
End If
If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Precision <> myTable.Columns.Item(intContador).Precision Then
strErrInfo = "Erro ao tentar actualizar a PRECISÃO de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).Precision = myTable.Columns.Item(intContador).Precision
End If

If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).RelatedColumn <> myTable.Columns.Item(intContador).RelatedColumn Then
strErrInfo = "Erro ao tentar actualizar a 'RELATED COLUMN' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).RelatedColumn = myTable.Columns.Item(intContador).RelatedColumn
End If
If tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).SortOrder <> myTable.Columns.Item(intContador).SortOrder Then
strErrInfo = "Erro ao tentar actualizar a 'SORTED ORDER' de campo na base dados " & m_bdDestino & " através da base de dados " & m_bdOrigem & " na tabela " & col.Name
tabelaDestino.Columns.Item(myTable.Columns.Item(intContador).Name).SortOrder = myTable.Columns.Item(intContador).SortOrder
End If
End If


DoEvents
Next intContador

For intIndex = 0 To tabelaDestino.Indexes.Count - 1
If intIndex > tabelaDestino.Indexes.Count - 1 Then Exit For
tabelaDestino.Indexes.Delete intIndex
DoEvents

Next intIndex

For intIndex = 0 To myTable.Indexes.Count - 1
'Set idx = tabelaDestino.Indexes td.CreateIndex(txtIndexName.Text)
Set ADOXindex = New ADOX.Index
strErrInfo = "Indice: " & myTable.Indexes(intIndex).Name
ADOXindex.Name = myTable.Indexes(intIndex).Name 'name of index


For intInnerIndex = 0 To myTable.Indexes(intIndex).Columns.Count - 1
strErrInfo = "Indice: " & myTable.Indexes(intIndex).Name & ", Coluna: " & myTable.Indexes(intIndex).Columns(intInnerIndex).Name
ADOXindex.Columns.Append myTable.Indexes(intIndex).Columns(intInnerIndex).Name ', myTable.Indexes(intIndex).Columns(intInnerIndex).Type, myTable.Indexes(intIndex).Columns(intInnerIndex).DefinedSize
'tabelaDestino.Indexes(intIndex).Columns.Append myTable.Indexes(intIndex).Columns(intInnerIndex).Name ', myTable.Indexes(intIndex).Columns(intInnerIndex).Type, myTable.Indexes(intIndex).Columns(intInnerIndex).DefinedSize
Next intInnerIndex
tabelaDestino.Indexes.Append ADOXindex
DoEvents
Next intIndex

Exit For
End If
Next

Exit Sub
ErrHandler:
If (Err.Description <> "O índice já existe.") And (InStr(Err.Description, "Não tem a autorização necessária para utilizar o objecto") = 0) And _
(InStr(Err.Description, "durante a sua abertura; mas a tabela não pode ser bloqueada enquanto estiver em utilização. Aguarde um momento e tente de novo.") = 0) And _
(Err.Description <> "A operação não é permitida neste contexto.") And _
(InStr(Err.Description, "Object variable or With block variable not set") = 0) And _
(InStr(Err.Description, "O método não é suportado por este fornecedor") = 0) And _
(InStr(Err.Description, "argumentos são de tipo incorrecto, estão fora do intervalo aceitável ou estão em conflito uns com os outros") = 0) And _
(InStr(Err.Description, "A operação de múltiplos passos OLE DB gerou erros. Verifique cada valor de estado OLE DB, se disponível") = 0) Then
intRegisto = intRegisto + 1
m_Lvw.ListItems.Add intRegisto, "A" & CStr(intRegisto), "BD:" & m_bdDestino & " " & strErrInfo & " (" & Err.Number & ") " & Err.Description
End If

Resume Next
End Sub

Reply With Quote
  #2  
Old May 7th, 2008, 07:10 AM
appdeveloper appdeveloper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 34 appdeveloper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 16 m 37 sec
Reputation Power: 2
readonly

Ok, so i found bugs in the code
i just can't do something like
col.Type = myTable.Columns.Item(intContador).Type

because col.Type is readonly
but if i can't do this, how can i change this property?

Reply With Quote
  #3  
Old May 7th, 2008, 11:22 AM
zynder's Avatar
zynder zynder is offline
Not much of a contributor
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: Hidden
Posts: 734 zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)zynder User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1Folding Points: 110329 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 9 h 19 m 57 sec
Reputation Power: 606
Send a message via Yahoo to zynder
Honestly, I haven't use ADO extension. I've heard it's quite useful but I never use it. The ADO is sufficient in my projects and I always create a reusable module that will do all stuff.

Try Googling it, it will return some hits or MSDN.

Reply With Quote
  #4  
Old May 7th, 2008, 11:21 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,546 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 14 h 57 m 13 sec
Reputation Power: 634
Please use forum CODE tags around posted code. Refer to these forums FAQ
__________________
======
Doug G
======
"Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Adox in vb6


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway