Class DatabaseReplacer
- Namespace
- Dynamicweb.Data
- Assembly
- Dynamicweb.Data.dll
This class contains functions to replace specified values in specified fields in a Database.
public class DatabaseReplacer
- Inheritance
-
DatabaseReplacer
- Inherited Members
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
replacer.PrimaryKeyField = "PageID"
''Optional
replacer.PrimaryKeyValue = "1"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
Database | Function to call |
---|---|
Do the replace | RunReplace |
Properties
Field
Sets or gets the name of the primary key field in the specified table to do the replace on
public string Field { get; set; }
Property Value
- string
- The name of the primary key field.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
.
PrimaryKeyField
Sets or gets the name of the field in the specified table to do the replace on
public string PrimaryKeyField { get; set; }
Property Value
- string
- The name of the field.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
.
PrimaryKeyValue
Sets or gets the value of the primarykey in the specified table to do the replace on
public string PrimaryKeyValue { get; set; }
Property Value
- string
- The primarykey of the column.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel where PageID = 1.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.PrimaryKeyValue = "1"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
If PrimaryKeyValue is specified the replace will only be run on the record matching this value.
Otherwise all records in the specified field in the table containing the ReplaceString will be replaced
ReplaceString
Sets or gets the string to replace.
public string ReplaceString { get; set; }
Property Value
- string
- The string to replace.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
Cannot be an empty string.
ReplaceWith
Sets or gets the string to replace with.
public string ReplaceWith { get; set; }
Property Value
- string
- The string to replace with.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Table
Sets or gets the name of table in the specified database to do the replace on.
public string Table { get; set; }
Property Value
- string
- The name of the table.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Methods
GetDataSet()
Gets a dataset of fields and their values for displaying what will be replaced.
public DataSet GetDataSet()
Returns
- DataSet
- DataSet.
Remarks
DataSet is disposed
ReplaceInDatabase(string, string, string, string, string, string)
Executes the replace on the database.
public string ReplaceInDatabase(string database, string table, string field, string primaryKeyField, string originalValue, string replaceValue)
Parameters
database
string- Name of database.
table
string- Name of table.
field
string- Name of field.
primaryKeyField
string- Name of primary key field.
originalValue
string- String to replace.
replaceValue
string- String to replace with.
Returns
- string
- Message with result of the replace with the number of records affected by replace.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
Dim numberOfRecordsAffected As Integer = replacer.RunReplace("Dynamic.mdb", "Page", "PageMenuText", "PageID", "MyString", "MyNewString")
Remarks
database, table, strField and strReplaceString must be specified.
RunReplace()
Executes the replace on the database.
public string RunReplace()
Returns
- string
- Message with result of the replace with the number of records affected by replace.
Examples
'' Do a replace of the value "MyString" with "MyNewString" on field "PageMenuText" in table "Page"
'' in the SQL-Database specified in control panel.
Dim replacer As New DatabaseReplacer()
replacer.Table = "Page"
replacer.Field = "PageMenuText"
replacer.PrimaryKeyField = "PageID"
replacer.ReplaceString = "MyString"
replacer.ReplaceWith = "MyNewString"
Dim numberOfRecordsAffected As Integer = replacer.RunReplace()
Remarks
Database, Table, Field and ReplaceString properties must be specified.
RunReplace(string, string, string, string, string, string)
[Obsolete("Use ReplaceInDatabase instead.")]
public string RunReplace(string database, string table, string strField, string strPrimaryKeyField, string strReplaceString, string strReplaceWith)
Parameters
database
stringtable
stringstrField
stringstrPrimaryKeyField
stringstrReplaceString
stringstrReplaceWith
string