lundi 2 mai 2016

Prepared Statement C#: Impossible casting of System.Data.SqlClient.SqlParameter object on System.Data.SQLite.SQLiteParameter?

In a C# application I've the following SQLiteDatabase:

"CREATE TABLE FOLDER(FolderPath TEXT," + "User TEXT," + "ParentPath TEXT," +
  "TimestampFolder DATETIME DEFAULT CURRENT_TIMESTAMP," + "TimestampParent DATETIME," 
+ "Present TEXT DEFAULT 'True'," + [...] )

During this prepared statement:

SQLiteCommand command = new SQLiteCommand(null, SQLconnection);
command.CommandText = "BEGIN TRANSACTION; "+ "INSERT INTO FOLDER (FolderPath, User, ParentPath, TimestampParent, Present)" + "VALUES (@uCpath, @uname, @pp, @date, @bool)" + "END TRANSACTION;";

SqlParameter unameParam = new SqlParameter("@uname", SqlDbType.Text, 100);
SqlParameter uCpathParam = new SqlParameter("@uCpath", SqlDbType.Text, 300);
SqlParameter uSpathParam = new SqlParameter("@uSpath", SqlDbType.Text, 300);
SqlParameter ppParam = new SqlParameter("@pp", SqlDbType.Text, 100);
SqlParameter dateParam = new SqlParameter("@date", SqlDbType.DateTime);
SqlParameter boolParam = new SqlParameter("@bool", SqlDbType.Text, 100);

unameParam.Value = user.Username;
uCpathParam.Value = user.ClientPath;
uSpathParam.Value = user.ServerPath;
ppParam.Value = null;
dateParam.Value = DateTime.MinValue.ToString("yyyy-MM-dd HH:mm:ss");
boolParam.Value = true.ToString();

command.Parameters.Add(unameParam);
command.Parameters.Add(uCpathParam);
command.Parameters.Add(uSpathParam);
command.Parameters.Add(ppParam);
command.Parameters.Add(dateParam);
command.Parameters.Add(boolParam);

command.Prepare();
command.ExecuteNonQuery();

The following run time exception is generated: Impossible the casting of 'System.Data.SqlClient.SqlParameter' object on 'System.Data.SQLite.SQLiteParameter'type.

I googled and I tried to change SqlDbType.DateTime with SqlDbType.DateTime2 or SqlDbType.Date or SqlDbType.TImestamp as well, but the same exception is launched. Any suggestion? Thanks

Aucun commentaire:

Enregistrer un commentaire