MySQL Forums
Forum List  »  Stored Procedures

Parameter not defined
Posted by: Angelica Kristensson
Date: November 26, 2008 12:17PM

Hi,

I've got a problem with storing values in a mysql database with the help of stored procedures.

My procedure looks like this:

CREATE PROCEDURE `InsertPager`( IN pDatum longtext, IN pRubrik longtext, IN pPages int, IN pFolder longtext, IN pPdfname longtext, IN pCounter int, IN pTidning varchar(255))
BEGIN
insert into pager
(datum, rubrik, pages, folder, pdfname, raknare, tidning)
values
(DATE(pDatum), pRubrik, pPages, pFolder, pPdfname, pCounter, pTidning);
select LAST_INSERT_ID();
END

In the .cs-file I have the following code:

cmd.CommandText = "InsertPager";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(GetParameter("pDatum", MySqlDbType.LongText));
result = (int)cmd.ExecuteScalar();

(GetParameter():, returns a MySqlParameter)
I get this exception:
Exception during execution of 'InsertPager': Parameter '?pDatum' is not defined

I get this because I havn't given the parameter any value. So I tried to do like this:

cmd.Parameters.Add((GetParameter("pDatum", MySqlDbType.LongText).Value = date.ToShortDateString()));

But then I got the following exception:
Only MySqlParameter objects may be stored.

Do you got any suggestion how I can solve this? I also tried to first create the parameter then assign the value and after that pass the parameter in the add()-method, but I still get the not defined exception.

Options: ReplyQuote


Subject
Views
Written By
Posted
Parameter not defined
4039
November 26, 2008 12:17PM
1843
November 26, 2008 01:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.