ObjectGears Help

           
Forum   ObjectGears (Version: 1.6.0.0)

Data object SqlParameterList

This object is used for definition of parameters passed over to a script. When using you will create instance of this object. After that you will define parameters by means of methods Add... and then pass this object to some function for SQL processing.

Object properties

Name Description
void AddNvarchar(string parameterName, string value) Method will add nvarchar parameter.
void AddInt(string parameterName, int value) Method will add int parameter.
void AddInt(string parameterName, long value) Method will add int parameter.
void AddNullInt(string parameterName, int? value) Method will add int parameter.
void AddFloat(string parameterName, double value) Method will add float parameter.
void AddNullFloat(string parameterName, double? value) Method will add float parameter.
void AddDateTime(string parameterName, DateTime value) Method will add dateTime parameter.
void AddNullDateTime(string parameterName, DateTime? value) Method will add dateTime parameter.
void AddTimeSpan(string parameterName, TimeSpan value) Method will add time parameter.
void AddNullTimeSpan(string parameterName, TimeSpan? value) Method will add time parameter.
void AddBit(string parameterName, bool value) Method will add bit parameter.
void AddNullBit(string parameterName, bool? value) Method will add bit parameter.
void AddUniqueIdentifier(string parameterName, Guid value) Method will add uniqueIdentifier parameter.
void AddNullUniqueIdentifier(string parameterName, Guid? value) Method will add uniqueIdentifier parameter.
void AddImage(string parameterName, byte[] value) Method will add image parameter.

Example

This example defines two parameters name and size, that will be used for finding out column of the given name and with value of the given size.

var sql = 'update .... where colname = @name and colsize > @size';

var p = OG.Sql.CreateParameterList();
p.AddNvarchar( 'name', 'Novak');
p.AddInt( 'size', 50);

OG.Sql.RunSql( null, sql, p);

Example of calling stored procedure

This example calls stored procedure sp_a, first without parameters and then with a parameter:

OG.Sql.RunSql( 'exec sp_a');

var pars = OG.Sql.CreateParameterList();
pars.AddInt('myData', 25);
OG.Sql.RunSql(  null, 'exec sp_a @myData', pars);

Stored procedure:

CREATE PROCEDURE sp_a
     @myData int = 11
AS
BEGIN
 SET NOCOUNT ON;
    insert mytable( data) values( @myData)
END

 

This website is using cookies files to provide services and analyse visits. You agree with that by using this website.     Further information