Show / Hide Table of Contents

PrepareSQLStatement Method (DbProvider)

The statement to prepare and format

The type of query being executed

Parameters for the parameterized query or stored procedure

Prepares and formats a SQL statement according to the rules of the underlying database type

Syntax

'Declaration

Public MustOverride Function PrepareSQLStatement( _
   ByVal _sqlStmt_ As String, _
   ByVal _cmdType_ As CommandType, _
   ByVal _commandParams_ As DataParameterCollection _
) As String
public abstract string PrepareSQLStatement( 
   string _sqlStmt_,
   CommandType _cmdType_,
   DataParameterCollection _commandParams_
)

Parameters

sqlStmt

The statement to prepare and format

cmdType

The type of query being executed

commandParams

Parameters for the parameterized query or stored procedure

Return Value

A formatted and prepared string, ready to be executed against the database

Remarks

This method will replace special tokens with statements or parameter names according to the type of query and parameters passed in. For example, the {DATE} token will be replaced with the database type's special date statement (as returned by the GetDateStatement Method). Parameters are specified using the {n} syntax where n is an ascending number. The number of {n} parameters must match the number of parameters specified in the commandParams argument.

For example, the string:

SELECT {DATE} AS CurDate FROM some_table WHERE name = {0} AND id = {1}

with the parameters named "nameVal" and "idVal" will be formatted as such with an MSSQL provider:

SELECT GETDATE() AS CurDate FROM some_table WHERE name = @nameVal AND id = @idVal

This statement can then be executed against the database using an ADO.NET IDbCommand instance, or the SqlHelper class.

NOTE: SqlHelper will automatically call this method during Execute* methods like ExecuteNonQuery or ExecuteDataSet. Generally, this method should not be called directly, only through SqlHelper.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server family

Reference

DbProvider Class
DbProvider Members

Back to top © 2022 Dovetail Software, Inc. - All rights reserved.
Clarify, Amdocs, and related products and names are copyright and trademark of Amdocs, Inc.
.NET, Visual Studio.NET, C#, Visual Basic and related products are trademark of Microsoft corporation.