Subject | Windows DateTime into Firebird Database |
---|---|
Author | ShofB |
Post date | 2006-03-10T01:48:02Z |
I'm having problems getting Windows DateTime into my Firebird DB. I defined the table as:
/* Table: PODCASTS, Owner: SYSDBA */
CREATE TABLE "PODCASTS"
(
"ID" INTEGER NOT NULL,
"FILENAME" VARCHAR(255) NOT NULL,
"DIRECTORY" INTEGER NOT NULL,
"USEMEDIA" CHAR(1) NOT NULL,
"FILETYPE" CHAR(5) NOT NULL,
"CREATIONDATE" TIMESTAMP NOT NULL,
"USED" CHAR(1) NOT NULL,
"FILESIZE" INTEGER NOT NULL,
PRIMARY KEY ("ID")
);
and a stored procedure to write a record as:
COMMIT WORK;
SET AUTODDL OFF;
SET TERM ^ ;
/* Stored procedures */
CREATE PROCEDURE "ADDPODCAST"
(
"ID" INTEGER,
"FILENAME" VARCHAR(255),
"DIRECTORY" INTEGER,
"FILESIZE" INTEGER,
"FILETYPE" CHAR(5),
"CREATIONDATE" TIMESTAMP,
"USEMEDIA" CHAR(1),
"USED" CHAR(1)
)
AS
BEGIN EXIT; END ^
ALTER PROCEDURE "ADDPODCAST"
(
"ID" INTEGER,
"FILENAME" VARCHAR(255),
"DIRECTORY" INTEGER,
"FILESIZE" INTEGER,
"FILETYPE" CHAR(5),
"CREATIONDATE" TIMESTAMP,
"USEMEDIA" CHAR(1),
"USED" CHAR(1)
)
AS
BEGIN
INSERT INTO podcasts (
id,filename,directory,filesize,filetype,creationdate,usemedia,used
) VALUES (
:id,:filename,:directory,:filesize,:filetype,:creationdate,:usemedia,:used
);
SUSPEND;
/* Notify listeners of insert */
POST_EVENT 'insert_sptable1_ins';
END
^
SET TERM ; ^
COMMIT WORK;
SET AUTODDL ON;
then in my C# program I do:
//
// path is the full path to the file
FileInfo fi = new FileInfo(path);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.CommandText = "ADDPODCAST";
cmd.Parameters.Add("@ID", ids[(int)FileTypes.Podcasts]++); // integer
cmd.Parameters.Add("@FILENAME", System.IO.Path.GetFileName(path).ToLower());
cmd.Parameters.Add("@DIRECTORY", dirID);
cmd.Parameters.Add("@FILESIZE", fi.Length);
cmd.Parameters.Add("@USEMEDIA", '0');
cmd.Parameters.Add("@USED", '0');
cmd.Parameters.Add("@FILETYPE",fileType);
cmd.Parameters.Add("@CREATIONDATE",fi.CreationTime.Date.ToFileTime()); // should be the file creation datetime
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Trace.WriteLine("Error writing record in AddPodcast " + ex.Message + " " + ex.InnerException);
}
Where there is a valid and open connection associted with the command. When I try and execute the procedure I get an exception that states:
[System.InvalidCastException] = {"Invalid cast from 'Char' to 'DateTime'."}.
Any help would be greatly appreciated. All I need to do is write the datatime that the file was created and then read. Seemss easy :-)
______________________________________________________________
Shof Beavers
"One mans magic is another mans science" - Lazarus Long
http://l_and_l.home.comcast.net/vfm.html
http://home.comcast.net/~shofb/unfinished.html
http://home.comcast.net/~shofb/tns.html
[Non-text portions of this message have been removed]
/* Table: PODCASTS, Owner: SYSDBA */
CREATE TABLE "PODCASTS"
(
"ID" INTEGER NOT NULL,
"FILENAME" VARCHAR(255) NOT NULL,
"DIRECTORY" INTEGER NOT NULL,
"USEMEDIA" CHAR(1) NOT NULL,
"FILETYPE" CHAR(5) NOT NULL,
"CREATIONDATE" TIMESTAMP NOT NULL,
"USED" CHAR(1) NOT NULL,
"FILESIZE" INTEGER NOT NULL,
PRIMARY KEY ("ID")
);
and a stored procedure to write a record as:
COMMIT WORK;
SET AUTODDL OFF;
SET TERM ^ ;
/* Stored procedures */
CREATE PROCEDURE "ADDPODCAST"
(
"ID" INTEGER,
"FILENAME" VARCHAR(255),
"DIRECTORY" INTEGER,
"FILESIZE" INTEGER,
"FILETYPE" CHAR(5),
"CREATIONDATE" TIMESTAMP,
"USEMEDIA" CHAR(1),
"USED" CHAR(1)
)
AS
BEGIN EXIT; END ^
ALTER PROCEDURE "ADDPODCAST"
(
"ID" INTEGER,
"FILENAME" VARCHAR(255),
"DIRECTORY" INTEGER,
"FILESIZE" INTEGER,
"FILETYPE" CHAR(5),
"CREATIONDATE" TIMESTAMP,
"USEMEDIA" CHAR(1),
"USED" CHAR(1)
)
AS
BEGIN
INSERT INTO podcasts (
id,filename,directory,filesize,filetype,creationdate,usemedia,used
) VALUES (
:id,:filename,:directory,:filesize,:filetype,:creationdate,:usemedia,:used
);
SUSPEND;
/* Notify listeners of insert */
POST_EVENT 'insert_sptable1_ins';
END
^
SET TERM ; ^
COMMIT WORK;
SET AUTODDL ON;
then in my C# program I do:
//
// path is the full path to the file
FileInfo fi = new FileInfo(path);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.CommandText = "ADDPODCAST";
cmd.Parameters.Add("@ID", ids[(int)FileTypes.Podcasts]++); // integer
cmd.Parameters.Add("@FILENAME", System.IO.Path.GetFileName(path).ToLower());
cmd.Parameters.Add("@DIRECTORY", dirID);
cmd.Parameters.Add("@FILESIZE", fi.Length);
cmd.Parameters.Add("@USEMEDIA", '0');
cmd.Parameters.Add("@USED", '0');
cmd.Parameters.Add("@FILETYPE",fileType);
cmd.Parameters.Add("@CREATIONDATE",fi.CreationTime.Date.ToFileTime()); // should be the file creation datetime
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Trace.WriteLine("Error writing record in AddPodcast " + ex.Message + " " + ex.InnerException);
}
Where there is a valid and open connection associted with the command. When I try and execute the procedure I get an exception that states:
[System.InvalidCastException] = {"Invalid cast from 'Char' to 'DateTime'."}.
Any help would be greatly appreciated. All I need to do is write the datatime that the file was created and then read. Seemss easy :-)
______________________________________________________________
Shof Beavers
"One mans magic is another mans science" - Lazarus Long
http://l_and_l.home.comcast.net/vfm.html
http://home.comcast.net/~shofb/unfinished.html
http://home.comcast.net/~shofb/tns.html
[Non-text portions of this message have been removed]