Parameter not defined
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.