不能將類型'object'隱式轉換爲'System.Data.SqlClient.SqlCommand'。在創建用戶控件將類型'object'轉換爲'System.Data.SqlClient.SqlCommand錯誤
正是在這樣的代碼的顯式轉換存在(是否缺少強制轉換?)
我得到這個錯誤。
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int Slno = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Value.ToString());
var ProductNum = gvDetails.DataKeys[e.RowIndex].Values["ProductNumber"].ToString();
TextBox txtShortDesc = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("ShortDesc");
SqlCommand cmd= SqlHelper.ExecuteScalar(GlobalSettings.DbDSN, CommandType.Text,"UPDATE sydShortDesc set ShortDesc='"+ txtShortDesc.Text+ " ' WHERE ProductNumber='"+ ProductNum +"' ");
cmd.ExecuteNonQuery();
lblresult.ForeColor = Color.Green;
lblresult.Text = username + " Details Updated successfully";
gvDetails.EditIndex = -1;
BindEmployeeDetails();
}