【VB/.NET】Converting VB6 to VB.NET [Part II] [넷]

14037 단어 convert

제4부분


원문


 

DLLs, DAO, RDO, ADO, and AD.NET; the History of VB DBs


In the early versions of VB, there were no database controls, and databases were accessed by vendor-specific DLLs, but VB's power and ease of creating forms still made it a favorite among database programmers. One thing that made it so easy to create forms in VB was VBXs, the forerunners of ActiveX controls. In VB3, Microsoft added DAO (Data Access Objects), allowing easy access to ODBC databases, and a good thing was started. RDO (Remote Data Objects) came next. Where DAO focused on connecting to small Access-type databases, RDO targeted a different market, large databases such as MS SQL and Oracle, so to a large extent RDO complemented rather than replaced DAO. ADO was to be the technology to combine the two.
 
Upgrading from the earlier DAO or RDO architectures will be difficult. The Data control that was typically used by DAO and RDO programmers is not supported by .NET, and the upgrade wizard just marks each place the data control is used with a comment that it is no longer supported. Following the comment to the documentation just leads to generic information about upgrading with no further help.
I have had some success creating an ActiveX control in VB6, adding the data control to the new ActiveX control, then adding functions and subroutines to make the data control accessible to its container in the VB client program. The accessors looked like
 
 Public Sub SetDataBaseName(Name As String) Data.DatabaseName = Name End Sub Public Sub SetRecordSource(Source As String) Data.RecordSource = Source End Sub Public Sub Refresh() Data.Refresh End Sub Public Sub RecordSetAddNew() Data.Recordset.AddNew End Sub Public Sub RecordSetFields(Field As String, Name As String) Data.Recordset.Fields(Field) = Name End Sub 

In the client VB program,
Data1.RecordSet.AddNew
was replaced with
Data1.RecordSetAddNew, Data1.Recordset.Fields("[Territory Num]") = RTrim(LTrim(txtTerritoryNum.Text))
which was replaced with
Data1.RecordSetFields "[Territory Num], RTrim(LTrim(txtTerritoryNum.Text)),
and so on. This worked well for strings, other RecordSetFields needed for other types of fields, or RecordSetField declared using Variant as the value type, and detecting the proper type by using the VarType function. This works all right if you just want to use the Data control by itself, but the whole point of using the Data control is to bind it to controls such as the DBGrid. To make that work correctly would require making the custom control a true VB data source. This is beyond the scope of this article, and might not work once converted to .NET. For anyone wishing to try this (and it might work), search for "Creating a Data Source"in the MSDN help files for more information.
I used a similar trick to convert a VB6 form to .NET. The form was designed to allow adding new records to an existing database. It could be considered as having three parts, a Data control for accessing the database, a DBGrid (from VB5) for displaying the records in the database, and a set of TextBoxes for inputting the values for the new record. I took the custom data control I created above and added a DBGrid (from VB5) to it. I included some resizing logic so that the grid always covered the entire control area. Next, I set the data source for grid to the data control and built the ActiveX control. I removed both the Data control and the DBGrid from the VB program I was converting, and replaced them with my new custom control containing both. It upgraded to VB.NET and ran fine. Again, being creative in using custom ActiveX controls can make otherwise impossible conversions fairly simple.
ADO.NET is one of the biggest changes yet in VB database connectivity. In ADO, programs were meant to always be connected to the database (note that ADO could be used in a disconnected mode, but most VB6 programs used the normal connected mode). In some ways, this simplified database programming a bit because changes made to records and tables in the program were automatically updated in the database. It also causes a scalability issue because one of the things most database vendors charge for is the number of allowed simultaneous connections. Since ADO connections tend to exist for the entire time the VB program is running, a license is tied up as well. Sometimes this does not matter, but if the program has a lot of users, or even worse, is accessed over the Internet, tying up a license for an extended time like this can get very expensive. Having a large number of open connections to the database can slow overall performance as well.
With ADO.NET, connections are opened to read, write, or update the database, and closed while the program or user works with the data. This causes a little more work for the programmer, but generates a slightly faster, and much more scalable program.
One half-step way to get around a complete rewrite is to switch to .NET, but continue to use ADO instead of ADO.NET. This can be done because ADO is implemented as a COM object in msado15.dll. Like all COM objects .NET needs a wrapper to access the ADO DLL. The .NET framework includes a wrapper for this DLL called adodb.dll, but you can also create your own from any version of ADO by using the tlbimport.exe utility that was briefly mentioned last month. Another option is, as always, that if a form can be separated from the rest of the application, it can be converted into an ActiveX control and added to a .NET form. Another advantage to using one of these techniques is that ADO has a few functions that are not available in ADO.NET, most notably server-side cursors and ADO extensions (ADOX).
I have already mentioned that moving from the connected ADO paradigm to the disconnected ADO.NET paradigm will give a boost in performance, and a big boost in scalability. There are other reasons to switch to ADO.NET, too. ADO uses recordsets that resemble tables; ADO.NET uses datasets that resemble databases. To access more than one table in ADO, the query forming the recordset had to do a join across the tables; in ADO.NET, the dataset can contain all the tables, as well as DataReleation objects, which resemble foreign keys in a real database. This can make complex data manipulations much easier. The old client-side Cursor functionality can still be found in the DataReader object. Another big difference is that while ADO can only load data into record sets, ADO.NET can also load data into many "normal"programming structures such as arrays and lists. Where ADO tables were accessed by forward only cursors, ADO.NET tables have indexers, and can be accessed like any other collection. Also, most of the .NET controls, even text boxes, allow data binding not to just text, but to other properties such as color (Note From the Author: This URL will only work if Visual Studio is installed on your computer) (see ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dnadvnet/html/vbnet02122002.htm).
Finally, ADO.NET is based on XML, which makes moving data between objects and programs easier and more efficient; using XML for this instead of ADO's COM calls also means that data can pass through firewalls without configuration changes.
 

Next Up


That completes our coverage of converting general and database code. Next month, in the final installment, we will cover ASP to ASP.NET conversion, and converting to VB.NET 2005 and C#; and conclude with some thoughts on when it makes sense to convert.
 

번역:


DLLs, DAO, RDO, ADO, AD.NET: VB DBs의 역사


이전 버전의 VB에는 데이터베이스 컨트롤이 없었고 공급업체별 DLL 파일을 통과해야 했다.그러나 VB의 강력한 성능과 창을 만드는 용이성은 데이터베이스 프로그래머들이 가장 선호하는 것이다.VB의 VBX (Visual Basic Extension) 는 창을 만드는 데 이렇게 쉽습니다. 이것은ActiveX 컨트롤의 전신입니다.VB3에서 마이크로소프트는 DAO(Data Access Object)를 추가하여 ODBC 데이터베이스에 접근하는 것을 더욱 편리하게 하였는데, 좋은 것이 이렇게 탄생하였다.이어 RDO(Remote Data Objects)가 나왔다.DAO는 주로 소형 접속식 데이터베이스에 연결되고 RDO는 MS SQL과 ORACLE 같은 대형 데이터베이스와 다른 시장을 대상으로 한다.따라서 RDO는 DAO의 빈자리를 어느 정도 메웠을 뿐 대체하는 것이 아니다.ADO는 양자의 결합체다.
초기의 DAO나 RDO 구조에서 업그레이드하는 것은 어려운 일이다.NET는 일반적으로 DAO와 RDO 프로그래머가 사용하는 DATA 컨트롤을 지원하지 않습니다. 또한 업그레이드 마법사는 이 컨트롤을 사용한 곳에 지원하지 않는다는 주석만 표시합니다.문서의 주석에 따르면 일반적인 정보를 얻었을 뿐 업그레이드에 큰 도움이 되지는 않는다.VB6에서, 나는 AX 컨트롤 프로젝트를 만들고 데이터 컨트롤을 추가할 수 있으며, 일부 함수, 과정도 추가할 수 있다.이 인터페이스는 이렇게 보인다.
 
Public Sub SetDataBaseName(Name As String) Data.DatabaseName = Name End Sub
 
  
Public Sub SetRecordSource(Source As String) Data.RecordSource = Source End Sub Public Sub Refresh() Data.Refresh End Sub Public Sub RecordSetAddNew() Data.Recordset.AddNew End Sub Public Sub RecordSetFields(Field As String, Name As String) Data.Recordset.Fields(Field) = Name End Sub

 
VB의 클라이언트 프로그램에서 다음을 수행합니다.
 
Data1.RecordSet.AddNew
  Data1.RecordSetAddNew  
 
  
Data1.Recordset.Fields("[Territory Num]") = RTrim(LTrim(txtTerritoryNum.Text))

  Data1.RecordSetFields "[Territory Num], RTrim(LTrim(txtTerritoryNum.Text))  
  。  String      ,   RecordSetFields         ,  RecordSetField             ,    VarType           。        DATA        ,       ,    DATA               DBGrid     。                            VB   ,             ,       .NET       。           (   ,            ),     NSDN       "Creating a Data Source"        。
                VB6   .NET。                       ,    ,       ,  DATA         ,  DBGrid( VB5)           ,                    。              DATA         DBGrid( VB5)。                ,               。  ,            ,     AX  。       ,  VB      DATA   DBGrid,                      。       VB.NET      。   ,      AX                      。
 VB       ADO.NET           。  ADO,              (  ADO           ,     VB6           )。     ,                                        。                ,                            。  ADO         VB           ,   License     。         ,            ,               ,                License        。                      。
  ADO.NET,                         、 、     、        。                  ,            ,          。
                .NET  ,       ADO   ADO.NET,ADO  MSADO15.DLL       COM         。     COM    ,.NET          ADO DLL,   adodb.dll,                   ADO  ,         tlbimport.exe        。     ,       ,                          ,            AX      .NET    。           ,  ADO     ADO.NET     ,         ADO  (ADOX)。
   ,      ADO        ADO.NET              ,           。       ADO.NET   。ADO          , ADO.NET            。 ADO          ,                      。 ADO.NET ,            DataReleation  (            )。                。             DataReader     。        , ADO              ADO.NET                 "  "     。   ADO          ,      ADO.NET     ,               。  ,   .NET  ,      ,            ,           (  :ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dnadvnet/html/vbnet02122002.htm)。
      ,ADO.NET   XML ,                       ;  XML   ADO COM                          。

다음 단계

                           。   ,           ASP ASP.NET   ,     VB.NET 2005 C#;                         。
 
  
 
  
 

좋은 웹페이지 즐겨찾기