SqlServerCeに小さな問題があります。以下のsqlStringを使用してExecuteNonQuery();を実行する場合。コマンド以下のエラーが発生します。
string sqlString = "INSERT INTO Images (UID, Name) " +
"VALUES ((SELECT ID FROM Contributors WHERE ID = @UID), @Name);";
このエラーが発生します:
There was an error parsing the query. [ Token line number = 1,Token line offset = 41,Token in error = SELECT ]
助言がありますか?
方法
public static void InsertImage(Contributor contObj, string ImageName)
{
string sqlString = "INSERT INTO Images (UID, Name) " +
"VALUES ((SELECT ID FROM [Contributors] WHERE ID = @UID), @Name);";
using (SqlCeConnection sqlConnection =
new SqlCeConnection(WebConfigurationManager.ConnectionStrings["DefaultSQL"].ConnectionString))
{
SqlCeCommand sqlCommand = new SqlCeCommand(sqlString, sqlConnection);
sqlCommand.Parameters.AddWithValue("@UID", contObj.ID);
sqlCommand.Parameters.AddWithValue("@Name", ImageName);
sqlConnection.Open();
sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
}
}