Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
准备好的语句C#:无法在System.Data.SQLite.SQLiteParameter上强制转换System.Data.SqlClient.SqlParameter对象?_C#_Sql_.net_Sqlite_Prepared Statement - Fatal编程技术网

准备好的语句C#:无法在System.Data.SQLite.SQLiteParameter上强制转换System.Data.SqlClient.SqlParameter对象?

准备好的语句C#:无法在System.Data.SQLite.SQLiteParameter上强制转换System.Data.SqlClient.SqlParameter对象?,c#,sql,.net,sqlite,prepared-statement,C#,Sql,.net,Sqlite,Prepared Statement,在C#应用程序中,我有以下SQLITE数据库: "CREATE TABLE FOLDER(FolderPath TEXT," + "User TEXT," + "ParentPath TEXT," + "TimestampFolder DATETIME DEFAULT CURRENT_TIMESTAMP," + "TimestampParent DATETIME," + "Present TEXT DEFAULT 'True'," + [...] ) 在本声明中: SQLiteComma

在C#应用程序中,我有以下SQLITE数据库:

"CREATE TABLE FOLDER(FolderPath TEXT," + "User TEXT," + "ParentPath TEXT," +
  "TimestampFolder DATETIME DEFAULT CURRENT_TIMESTAMP," + "TimestampParent DATETIME," 
+ "Present TEXT DEFAULT 'True'," + [...] )
在本声明中:

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();
将生成以下运行时异常: 无法在“System.Data.SQLite.SQLiteParameter”类型上强制转换“System.Data.SqlClient.SqlParameter”对象

我在谷歌上搜索,试图用SqlDbType.DateTime2或SqlDbType.Date或SqlDbType.TImestamp更改SqlDbType.DateTime,但启动了相同的异常。有什么建议吗?
谢谢

您正在不同数据库类型之间混合类

如果要连接到SQLite数据库,则必须使用相应的类,但使用的是SQL Server类层次结构中的
SqlParameter


只需将代码中的
SqlParameter
替换为
SQLiteParameter
,它就会工作得更好。

SqlParameter unaparam=…
更改为
SQLiteParameter unaparam=…
…做得好。我还有一个相关的问题。如果这样做,则会出现错误:error CS1503参数2:无法从“System.Data.SqlDbType”转换为“System.Data.DbType”。因此,我按照建议将SqlDbType更改为DbType,但DbType没有字段文本。我该怎么办?感谢lotSQLite没有
Text
数据类型,只需使用string即可。