SCM

[#1006908] stored procedure with Money parameter - exception

View Trackers | Bugs | Download .csv | Monitor

Date:
2007-06-23 21:38
Priority:
3
State:
Open
Submitted by:
Nobody
Assigned to:
Nobody (None)
Npgsql Version:
1.0
Category:
Group:
Resolution:
None
Summary:
stored procedure with Money parameter - exception

Detailed description
It seems to be a problem with calling stored procedure that has Money parameter.
This code generates exception: "Object reference not set to an instance of an object."

[C#]
NpgsqlConnection conn = new NpgsqlConnection(connString);
NpgsqlCommand updateCmd = new NpgsqlCommand(
"myStoredProcedure(@id1, @id2
, @money_param)", conn);

updateCmd.CommandType = CommandType.StoredProcedure;
updateCmd.Parameters.Add("@id1", NpgsqlTypes.NpgsqlDbType.Integer);
updateCmd.Parameters.Add("@id2", NpgsqlTypes.NpgsqlDbType.Integer);
updateCmd.Parameters.Add("@money_param", NpgsqlTypes.NpgsqlDbType.Money);

updateCmd.Parameters["@id1"].Value = 1;
updateCmd.Parameters["@id_typu"].Value = 7;
updateCmd.Parameters["@wartosc_cennika"].Value = decimal.Parse(textBox1.Text);

updateCmd.ExecuteNonQuery(); //here occures exception
//or updateCmdExecuteReader();

conn.Close();
[/C#]

stored procedure:
[SQL]

CREATE OR REPLACE FUNCTION myStoredProcedure( integer, integer, money )
RETURNS integer
AS
$BODY$
DECLARE
id1 ALIAS FOR $1;
id2 ALIAS FOR $2;
money_param ALIAS FOR $3;
BEGIN
IF NOT EXISTS (SELECT * FROM my_table WHERE id_1=id1 AND id_2=id2)
THEN
INSERT INTO my_table VALUES (id1, id2, money_param);
RETURN 1;
END IF;

RETURN -1;
END;

$BODY$
LANGUAGE 'plpgsql';

[/SQL]


or any other stored function with money parameter

everything works fine if it is not a stored procedure (for example "update table ...........")

at the moment i have to call that procedure with this way:
[C#]
NpgsqlCommand updateCmd = new NpgsqlCommand(
"SELECT myStoredProcedure(@id1, @id2
, @money_param)", conn);
updateCmd.CommandType = CommandType.Text;
//....adding parameters
updateCmd.ExecuteNonQuery();
[/C#]

Followup

No Followups Have Been Posted

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge