ListView でテキストを編集し、その後データベースで更新しようとすると、このエラーが発生します。このエラー メッセージは、ListView の更新ボタンをクリックすると表示されます。私の UserID は uniqueIdentifier であるため、データベースに更新できません。しかし、コードにどのような変更を加える必要があるのか よくわかりません。
私のエラーメッセージはこれを示しています:
Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.
.cs の私の SQL ステートメント:
protected void updateComment(object sender, ListViewUpdateEventArgs e)
{
MembershipUser currentUser = Membership.GetUser();
Guid currentUserId = (Guid)currentUser.ProviderUserKey;
var ID= ListView1.DataKeys[e.ItemIndex].Value.ToString();
string connectionString = ConfigurationManager.ConnectionStrings["ASPNETConnectionString"].ConnectionString;
SqlConnection myConnect = new SqlConnection(connectionString);
string updateSql = "UPDATE Review set ContentRev =@ContentRev WHERE ID = @ID";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand(updateSql, myConnection);
myCommand.Parameters.AddWithValue("@ID", ID);
myCommand.Parameters.AddWithValue("@ContentRev ", TextBox1.Text.Trim());
myCommand.ExecuteNonQuery();
myConnection.Close();
ListView1.DataBind();
}
Userid のデータ型は Object で、ContentRev は String です。