I tested this method for the string parameter alone, and it worked perfectly. So I am sure there is a mistake in setting up the parameter of type DateTime (datapubl), which I added later. Thank you in advance!
By the way, the CatalogCreateFilmsTest sproc was executed and works OK.
Anna
public static bool CreateFilmTest(string nume, string datapubl)
{
DbCommand com = GenericDataAccess.CreateCommand();
com.CommandText = "CatalogCreateFilmTest";
DbParameter param = com.CreateParameter();
param.ParameterName = "@nume";
param.Value = nume;
param.DbType = DbType.String;
param.Size = 200;
com.Parameters.Add(param);
param = com.CreateParameter();
param.ParameterName = "@datapubl";
param.Value = datapubl;
param.DbType = DbType.DateTime;
com.Parameters.Add(param);
int result = -1;
try
{
result = GenericDataAccess.ExecuteNonQuery(com);
}
catch
{
//
}
return (result >= 1);
}
EDIT: The problem is the stored procedure is not even executed (it should insert rows into a table but doesn't) . No error, but not the correct result either.
EDIT: Chris, here is the full example:
CREATE PROCEDURE CatalogCreateFilmTest(
@nume nvarchar(1500),
@datapubl datetime
)
AS
INSERT INTO Filme
(nume, datapubl)
VALUES
(@nume, @datapubl)
;
GO
which works for:
EXEC CatalogCreateFilmTest 'achu', '';
I then call CreateFilmTest like this:
bool success = FilmsAccess.CreateFilmTest(newNume.Text, null);
or:
bool success = FilmsAccess.CreateFilmTest(newNume.Text, DateTime.Now.ToString());
In both cases, the ExecuteNonQuery doesn't run.
com.CommandType = CommandType.StoredProcedure? You say that theExecuteNonQuerydoesn't run. Do you mean that the line of code isn't executed? Or that the query is run but doesn't do anything? Also, if the data type in SQL isDateTime, then you probably don't want to pass a string.