當我嘗試在ListView中編輯我的文本並隨後在數據庫中更新它時,我正面臨此錯誤。此錯誤消息顯示當我點擊ListView中的更新按鈕時。由於我的UserID是唯一標識符,因此無法更新到我的數據庫。但我真的不知道在我的代碼中做了哪些更改。System.Data.SqlClient.SqlException:不允許將數據類型sql_variant隱式轉換爲uniqueidentifier。
我的錯誤信息表明這一點:在的.cs
Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.
我的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 [email protected] 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();
}
我的用戶ID數據類型是對象和ContentRev是字符串。
不確定你爲什麼提到用戶的ID?它不是SQL的一部分。 – 2012-07-31 12:58:16