The following describes how to use ADO. Net to update the Geodatabase and shapefile attribute tables,
Here, we only take updating a single column as an example. Of course you can extend it and write different SQL statements to meet your requirements.
''' <Summary>
''' Update a column of a table in MDB as a specified string.
''' </Summary>
''' <Param name = "pdatabasename"> MDB path </param>
''' <Param name = "ptablename"> table name </param>
''' <Param name = "pcolumnname"> column name </param>
''' <Remarks> in this example, you can use ADO. Net to update an MDB Attribute Table, which is very fast. </remarks>
Private shared sub updatemdbtable (byval pdatabasename as string, byval ptablename as string, byval pcolumnname as string)
''Establish a connection with MDB
Dim poledbcon as new oledb. oledbconnection ("provider = Microsoft. Jet. oledb.4.0; Data Source =" & pdatabasename)
''Open connection
Poledbcon. open ()
''Create the command to update the table in MDB.
Dim poledbcom as new oledb. oledbcommand ("Update" & ptablename & "set" & pcolumnname & "= 'teyun db'", poledbcon)
''Run the SQL statement
Poledbcom. executenonquery ()
''Close the connection
Poledbcon. Close ()
End sub
''' <Summary>
''' Update a column in DBF as a unified string.
''' </Summary>
''' <Param name = "pdatapath"> path of the DBF parent folder </param>
''' <Param name = "ptablename"> DBF table name (that is, file name) </param>
''' <Param name = "pcolumnname"> name of the column to be updated in DBF </param>
''' <Remarks> This method is used to open the connection of oledb, which is more common. This example provides a method to operate the DBF file in the shapefile Attribute Table, using ADO. net updates the Attribute Table, which is very fast </remarks>
Private shared sub updatedbftable (byval pdatapath as string, byval ptablename as string, byval pcolumnname as string)
''Establish a connection with DBF
Dim poledbcon as new oledb. oledbconnection ("provider = Microsoft. jet. oledb.4.0; Data Source = "& pdatapath &"; extended properties = dbase iv; user id = admin; Password = ;")
''Open connection
Poledbcon. open ()
''Create a command to update the corresponding columns in the DBF table. Note that the table name in the SQL statement must be the full-path table name of DBF; otherwise, an error occurs.
Dim ptablepath as string = pdatapath & "\" & ptablename & ". DBF"
Dim poledbcom as new oledb. oledbcommand ("Update" & ptablepath & "set" & pcolumnname & "= 'testdbf'", poledbcon)
''This method also works,Dim poledbcom as new oledb. oledbcommand ("Update [" & ptablename & "] Set" & pcolumnname & "= 'testdbf'", poledbcon)
''Run the SQL statement
Poledbcom. executenonquery ()
''Close the connection
Poledbcon. Close ()
End sub
''' <Summary>
''' Update a column in DBF as a unified string.
''' </Summary>
''' <Param name = "pdbftablepath"> DBF path (including the DBF File Name) </param>
''' <Param name = "pcolumnname"> name of the column to be updated in DBF </param>
''' <Remarks> This example provides a method to operate the DBF file of the shapefile Attribute Table. It uses ADO. Net to update the Attribute Table very quickly. </remarks>
Private shared sub updatedbftable (byval pdbftablepath as string, byval pcolumnname as string)
''Establish a connection with DBF
Dim podbccon as new ODBC. odbcconnection ("provider = msdasql.1; driver = Microsoft Visual FoxPro driver; sourcedb =" & pdbftablepath & "; sourcetype = DBF ;")
''Open connection
Podbccon. open ()
''Create a command to update the corresponding columns in the DBF table. Note that the table name in the SQL statement must be the full-path table name of DBF; otherwise, an error occurs.
Dim podbccom as new ODBC. odbccommand ("Update" & pdbftablepath & "set" & pcolumnname & "= 'testdbf'", podbccon)
''Run the SQL statement
Podbccom. executenonquery ()
''Close the connection
Podbccon. Close ()
End sub
''' <Summary>
''' Update a column in the Attribute Table of the database-type featurelayer as a specific string.
''' </Summary>
''' <Param name = "Player"> featurelayer </param>
''' <Param name = "ptablename"> table name </param>
''' <Param name = "pcolumnname"> column name </param>
''' <Remarks> This method cannot be used to update the Attribute Table of the shapefile. </remarks>
Private shared sub updatetable (byval player as ifeaturelayer, byval ptablename as string, byval pcolumnname as string)
Dim pdataset as idataset = player. featureclass
Pdataset. workspace. executesql ("Update" & ptablename & "set" & pcolumnname & "= 'mdb '")
End sub